create-windy 0.8.3 → 0.10.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 +2714 -1944
- package/package.json +2 -2
- package/template/.agents/skills/windy-business-module/SKILL.md +33 -1
- package/template/.windy-template.json +6 -2
- package/template/AGENTS.md +4 -0
- package/template/README.md +2 -0
- package/template/apps/agent-server/Dockerfile +92 -22
- package/template/apps/agent-server/README.md +47 -85
- package/template/apps/agent-server/documents/office.py +216 -0
- package/template/apps/agent-server/documents/query_report.py +136 -0
- package/template/apps/agent-server/documents/smoke.py +177 -0
- package/template/apps/agent-server/documents/test_boundaries.py +185 -0
- package/template/apps/agent-server/host-contracts.ts +56 -0
- package/template/apps/agent-server/install-native.ts +167 -0
- package/template/apps/agent-server/main.ts +179 -0
- package/template/apps/agent-server/native/EXTENSIONS.md +46 -0
- package/template/apps/agent-server/native/admission.ts +73 -0
- package/template/apps/agent-server/native/authorization.test.ts +176 -0
- package/template/apps/agent-server/native/authorization.ts +118 -0
- package/template/apps/agent-server/native/boundary-io.ts +93 -0
- package/template/apps/agent-server/native/boundary-product.ts +107 -0
- package/template/apps/agent-server/native/boundary-project.test.ts +247 -0
- package/template/apps/agent-server/native/boundary-project.ts +188 -0
- package/template/apps/agent-server/native/boundary.ts +188 -0
- package/template/apps/agent-server/native/compaction-policy.test.ts +175 -0
- package/template/apps/agent-server/native/config.ts +95 -0
- package/template/apps/agent-server/native/conversation-instructions.ts +9 -0
- package/template/apps/agent-server/native/extensions.test.ts +190 -0
- package/template/apps/agent-server/native/extensions.ts +31 -0
- package/template/apps/agent-server/native/host-profile.test.ts +91 -0
- package/template/apps/agent-server/native/host-profile.ts +33 -0
- package/template/apps/agent-server/native/host-test-fixture.ts +13 -0
- package/template/apps/agent-server/native/http.ts +129 -0
- package/template/apps/agent-server/native/lifecycle.test.ts +285 -0
- package/template/apps/agent-server/native/lifecycle.ts +136 -0
- package/template/apps/agent-server/native/manager.ts +292 -0
- package/template/apps/agent-server/native/native.test.ts +207 -0
- package/template/apps/agent-server/native/office-preview.test.ts +50 -0
- package/template/apps/agent-server/native/office-preview.ts +25 -0
- package/template/apps/agent-server/native/parallel-harness.ts +244 -0
- package/template/apps/agent-server/native/parallel-mcp-fixture.ts +97 -0
- package/template/apps/agent-server/native/parallel.test.ts +256 -0
- package/template/apps/agent-server/native/profile-composition.test.ts +147 -0
- package/template/apps/agent-server/native/profile.ts +307 -0
- package/template/apps/agent-server/native/request.ts +61 -0
- package/template/apps/agent-server/native/session-conflict.test.ts +235 -0
- package/template/apps/agent-server/native/session-conflict.ts +21 -0
- package/template/apps/agent-server/native/shared-skills.test.ts +128 -0
- package/template/apps/agent-server/native/shared-skills.ts +240 -0
- package/template/apps/agent-server/native/socket-lifecycle.test.ts +48 -0
- package/template/apps/agent-server/native/socket.ts +130 -0
- package/template/apps/agent-server/native/storage-lifecycle.test.ts +218 -0
- package/template/apps/agent-server/native/storage.ts +188 -0
- package/template/apps/agent-server/native/stream-authorization.test.ts +89 -0
- package/template/apps/agent-server/native/worker.ts +77 -0
- package/template/apps/agent-server/native-download.test.ts +119 -0
- package/template/apps/agent-server/native-download.ts +145 -0
- package/template/apps/agent-server/package.json +64 -0
- package/template/apps/agent-server/plugins/access.mjs +126 -0
- package/template/apps/agent-server/plugins/branding/README.md +9 -0
- package/template/apps/agent-server/plugins/branding/brand.css +85 -0
- package/template/apps/agent-server/plugins/branding/client.js +338 -0
- package/template/apps/agent-server/plugins/branding/index.mjs +35 -0
- package/template/apps/agent-server/plugins/branding/loading.d.mts +2 -0
- package/template/apps/agent-server/plugins/branding/loading.mjs +66 -0
- package/template/apps/agent-server/plugins/branding/loading.test.ts +89 -0
- package/template/apps/agent-server/plugins/branding/package.json +21 -0
- package/template/apps/agent-server/plugins/branding.test.ts +294 -0
- package/template/apps/agent-server/plugins/compaction.mjs +83 -0
- package/template/apps/agent-server/plugins/compaction.test.ts +91 -0
- package/template/apps/agent-server/plugins/confine-network.py +57 -0
- package/template/apps/agent-server/plugins/default-skills.test.ts +62 -0
- package/template/apps/agent-server/plugins/downloads/README.md +28 -0
- package/template/apps/agent-server/plugins/downloads/client.js +126 -0
- package/template/apps/agent-server/plugins/downloads/downloads.test.ts +222 -0
- package/template/apps/agent-server/plugins/downloads/index.d.mts +19 -0
- package/template/apps/agent-server/plugins/downloads/index.mjs +180 -0
- package/template/apps/agent-server/plugins/downloads/package.json +20 -0
- package/template/apps/agent-server/plugins/drop-overlay/README.md +24 -0
- package/template/apps/agent-server/plugins/drop-overlay/drop-overlay.test.ts +199 -0
- package/template/apps/agent-server/plugins/drop-overlay/index.d.mts +8 -0
- package/template/apps/agent-server/plugins/drop-overlay/index.mjs +12 -0
- package/template/apps/agent-server/plugins/drop-overlay/style.css +102 -0
- package/template/apps/agent-server/plugins/locale/client.js +61 -0
- package/template/apps/agent-server/plugins/locale/index.d.mts +9 -0
- package/template/apps/agent-server/plugins/locale/index.mjs +16 -0
- package/template/apps/agent-server/plugins/locale/locale.test.ts +217 -0
- package/template/apps/agent-server/plugins/locale/package.json +19 -0
- package/template/apps/agent-server/plugins/parallel.mjs +146 -0
- package/template/apps/agent-server/plugins/preset-registry.d.mts +2 -0
- package/template/apps/agent-server/plugins/preset-registry.mjs +41 -0
- package/template/apps/agent-server/plugins/preset-registry.test.ts +46 -0
- package/template/apps/agent-server/plugins/questions.d.mts +25 -0
- package/template/apps/agent-server/plugins/questions.mjs +142 -0
- package/template/apps/agent-server/plugins/questions.test.ts +105 -0
- package/template/apps/agent-server/plugins/settings/README.md +17 -0
- package/template/apps/agent-server/plugins/settings/client.js +102 -0
- package/template/apps/agent-server/plugins/settings/index.mjs +17 -0
- package/template/apps/agent-server/plugins/settings/package.json +19 -0
- package/template/apps/agent-server/plugins/settings/settings.test.ts +129 -0
- package/template/apps/agent-server/plugins/settings-controller.d.mts +4 -0
- package/template/apps/agent-server/plugins/settings-controller.mjs +31 -0
- package/template/apps/agent-server/plugins/settings-controller.test.ts +17 -0
- package/template/apps/agent-server/plugins/settings-dispatch.test.ts +34 -0
- package/template/apps/agent-server/plugins/shared-skills.d.mts +15 -0
- package/template/apps/agent-server/plugins/shared-skills.mjs +82 -0
- package/template/apps/agent-server/plugins/shared-skills.test.ts +51 -0
- package/template/apps/agent-server/plugins/skill-library/README.md +11 -0
- package/template/apps/agent-server/plugins/skill-library/archive.test.ts +43 -0
- package/template/apps/agent-server/plugins/skill-library/bundle.mjs +234 -0
- package/template/apps/agent-server/plugins/skill-library/client-chunks.test.ts +110 -0
- package/template/apps/agent-server/plugins/skill-library/client-form-mount.test.ts +139 -0
- package/template/apps/agent-server/plugins/skill-library/client-form.test.ts +261 -0
- package/template/apps/agent-server/plugins/skill-library/client-ui.test.ts +268 -0
- package/template/apps/agent-server/plugins/skill-library/client-use.test.ts +158 -0
- package/template/apps/agent-server/plugins/skill-library/client.editor.js +93 -0
- package/template/apps/agent-server/plugins/skill-library/client.form.js +316 -0
- package/template/apps/agent-server/plugins/skill-library/client.js +348 -0
- package/template/apps/agent-server/plugins/skill-library/client.request.js +52 -0
- package/template/apps/agent-server/plugins/skill-library/client.transfer.js +48 -0
- package/template/apps/agent-server/plugins/skill-library/client.use.js +46 -0
- package/template/apps/agent-server/plugins/skill-library/default-roots.test.ts +84 -0
- package/template/apps/agent-server/plugins/skill-library/draft.d.mts +17 -0
- package/template/apps/agent-server/plugins/skill-library/draft.mjs +152 -0
- package/template/apps/agent-server/plugins/skill-library/draft.test.ts +287 -0
- package/template/apps/agent-server/plugins/skill-library/index.d.mts +49 -0
- package/template/apps/agent-server/plugins/skill-library/index.mjs +226 -0
- package/template/apps/agent-server/plugins/skill-library/package.json +24 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/README.md +27 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/UPSTREAM.md +54 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/boot.test.ts +150 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/client.js +146 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/client.test.ts +195 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/index.d.mts +9 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/index.mjs +30 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/metadata.test.ts +82 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/package.json +21 -0
- package/template/apps/agent-server/plugins/skill-library/presentation/react-boot.test.ts +162 -0
- package/template/apps/agent-server/plugins/skill-library/skills.test.ts +342 -0
- package/template/apps/agent-server/plugins/skill-library/storage.mjs +293 -0
- package/template/apps/agent-server/plugins/skill-library/style.css +229 -0
- package/template/apps/agent-server/plugins/skill-library/test-fixture.ts +77 -0
- package/template/apps/agent-server/plugins/skill-library/workflow.d.mts +18 -0
- package/template/apps/agent-server/plugins/skill-library/workflow.mjs +189 -0
- package/template/apps/agent-server/plugins/skill-library/workflow.test.ts +164 -0
- package/template/apps/agent-server/plugins/skills/README.md +5 -0
- package/template/apps/agent-server/plugins/skills/windy-data-summary/SKILL.md +14 -0
- package/template/apps/agent-server/plugins/skills/windy-extension-guide/SKILL.md +14 -0
- package/template/apps/agent-server/plugins/skills/windy-office/SKILL.md +14 -0
- package/template/apps/agent-server/plugins/skills/windy-skill-capture/SKILL.md +14 -0
- package/template/apps/agent-server/plugins/skills/windy-source-compare/SKILL.md +14 -0
- package/template/apps/agent-server/plugins/subprocess.mjs +40 -0
- package/template/apps/agent-server/plugins/theme/README.md +22 -0
- package/template/apps/agent-server/plugins/theme/client.js +18 -0
- package/template/apps/agent-server/plugins/theme/index.d.mts +9 -0
- package/template/apps/agent-server/plugins/theme/index.mjs +18 -0
- package/template/apps/agent-server/plugins/theme/package.json +19 -0
- package/template/apps/agent-server/plugins/theme/source-tokens.ts +81 -0
- package/template/apps/agent-server/plugins/theme/sync-tokens.ts +12 -0
- package/template/apps/agent-server/plugins/theme/theme.test.ts +193 -0
- package/template/apps/agent-server/plugins/theme/tokens.json +162 -0
- package/template/apps/agent-server/plugins/tool-catalog/README.md +82 -0
- package/template/apps/agent-server/plugins/tool-catalog/categories.mjs +111 -0
- package/template/apps/agent-server/plugins/tool-catalog/categories.test.ts +118 -0
- package/template/apps/agent-server/plugins/tool-catalog/client-cache.test.ts +264 -0
- package/template/apps/agent-server/plugins/tool-catalog/client.js +333 -0
- package/template/apps/agent-server/plugins/tool-catalog/client.test.ts +136 -0
- package/template/apps/agent-server/plugins/tool-catalog/discovery.d.mts +42 -0
- package/template/apps/agent-server/plugins/tool-catalog/discovery.mjs +245 -0
- package/template/apps/agent-server/plugins/tool-catalog/discovery.test.ts +291 -0
- package/template/apps/agent-server/plugins/tool-catalog/index.d.mts +5 -0
- package/template/apps/agent-server/plugins/tool-catalog/index.mjs +91 -0
- package/template/apps/agent-server/plugins/tool-catalog/package.json +23 -0
- package/template/apps/agent-server/plugins/tool-catalog/presentation.d.mts +21 -0
- package/template/apps/agent-server/plugins/tool-catalog/presentation.mjs +153 -0
- package/template/apps/agent-server/plugins/tool-catalog/presentation.test.ts +166 -0
- package/template/apps/agent-server/plugins/tool-catalog/routes.test.ts +209 -0
- package/template/apps/agent-server/plugins/tool-catalog/style.css +155 -0
- package/template/apps/agent-server/plugins/tool-catalog/use-tool.test.ts +160 -0
- package/template/apps/agent-server/plugins/tool-presentation/README.md +7 -0
- package/template/apps/agent-server/plugins/tool-presentation/build-client.ts +29 -0
- package/template/apps/agent-server/plugins/tool-presentation/client.js +312 -0
- package/template/apps/agent-server/plugins/tool-presentation/client.results.js +9 -0
- package/template/apps/agent-server/plugins/tool-presentation/client.test.ts +178 -0
- package/template/apps/agent-server/plugins/tool-presentation/index.mjs +10 -0
- package/template/apps/agent-server/plugins/tool-presentation/package.json +24 -0
- package/template/apps/agent-server/plugins/tool-presentation/result-discovery.mjs +43 -0
- package/template/apps/agent-server/plugins/tool-presentation/result-model.d.mts +51 -0
- package/template/apps/agent-server/plugins/tool-presentation/result-model.mjs +96 -0
- package/template/apps/agent-server/plugins/workspace/README.md +5 -0
- package/template/apps/agent-server/plugins/workspace/index.mjs +8 -0
- package/template/apps/agent-server/plugins/workspace/package.json +10 -0
- package/template/apps/agent-server/plugins/workspace/style.css +124 -0
- package/template/apps/agent-server/project/host.ts +13 -0
- package/template/apps/agent-server/runtime/artifacts.ts +115 -0
- package/template/apps/agent-server/runtime/audit.nodecheck.ts +60 -0
- package/template/apps/agent-server/runtime/capacity.ts +61 -0
- package/template/apps/agent-server/runtime/client-completion-budget.nodecheck.ts +92 -0
- package/template/apps/agent-server/runtime/compatibility.ts +39 -0
- package/template/apps/agent-server/runtime/completions.ts +320 -0
- package/template/apps/agent-server/runtime/config.ts +246 -0
- package/template/apps/agent-server/runtime/context-budget.ts +70 -0
- package/template/apps/agent-server/runtime/context-plugin.ts +306 -0
- package/template/apps/agent-server/runtime/context.nodecheck.ts +241 -0
- package/template/apps/agent-server/runtime/contracts.ts +201 -0
- package/template/apps/agent-server/runtime/dsh-engine.ts +198 -0
- package/template/apps/agent-server/runtime/evaluation-plugin.ts +115 -0
- package/template/apps/agent-server/runtime/evaluation.nodecheck.ts +194 -0
- package/template/apps/agent-server/runtime/events.ts +71 -0
- package/template/apps/agent-server/runtime/governance.ts +194 -0
- package/template/apps/agent-server/runtime/index.ts +339 -0
- package/template/apps/agent-server/runtime/internal-output.ts +37 -0
- package/template/apps/agent-server/runtime/isolation.nodecheck.ts +287 -0
- package/template/apps/agent-server/runtime/model-payload.ts +97 -0
- package/template/apps/agent-server/runtime/model-plugin.ts +308 -0
- package/template/apps/agent-server/runtime/model-route.ts +34 -0
- package/template/apps/agent-server/runtime/model-usage.ts +51 -0
- package/template/apps/agent-server/runtime/model-wire.ts +45 -0
- package/template/apps/agent-server/runtime/native-authorization.nodecheck.ts +126 -0
- package/template/apps/agent-server/runtime/native-completion.nodecheck.ts +81 -0
- package/template/apps/agent-server/runtime/output-validation.ts +66 -0
- package/template/apps/agent-server/runtime/production-capacity.nodecheck.ts +121 -0
- package/template/apps/agent-server/runtime/questions-workflow.nodecheck.ts +251 -0
- package/template/apps/agent-server/runtime/report-breakdown.ts +79 -0
- package/template/apps/agent-server/runtime/reporting.ts +219 -0
- package/template/apps/agent-server/runtime/run-completion.ts +39 -0
- package/template/apps/agent-server/runtime/run-request-digest.ts +18 -0
- package/template/apps/agent-server/runtime/runtime-test-fixtures.ts +264 -0
- package/template/apps/agent-server/runtime/runtime.nodecheck.ts +150 -0
- package/template/apps/agent-server/runtime/store-idempotency.nodecheck.ts +74 -0
- package/template/apps/agent-server/runtime/store.ts +324 -0
- package/template/apps/agent-server/runtime/structured-output-mode.nodecheck.ts +51 -0
- package/template/apps/agent-server/runtime/tool-name.ts +6 -0
- package/template/apps/agent-server/runtime/tool-plugin.ts +201 -0
- package/template/apps/agent-server/runtime/vision-readiness.ts +200 -0
- package/template/apps/agent-server/scripts/confinement-check.mjs +103 -0
- package/template/apps/agent-server/scripts/coordinator-check.mjs +344 -0
- package/template/apps/agent-server/scripts/documents-delivery-check.mjs +309 -0
- package/template/apps/agent-server/scripts/office-preview-check.mjs +92 -0
- package/template/apps/agent-server/scripts/test-confinement.ts +58 -0
- package/template/apps/agent-server/scripts/test-coordinator.ts +36 -0
- package/template/apps/agent-server/scripts/test-runtime.ts +46 -0
- package/template/apps/agent-server/tsconfig.json +21 -0
- package/template/apps/server/Dockerfile +5 -1
- package/template/apps/server/package.json +14 -10
- package/template/apps/server/scripts/check-dsh-platform-example.ts +251 -0
- package/template/apps/server/scripts/validate-module-composition-once.ts +2 -0
- package/template/apps/server/scripts/validate-module-composition.ts +8 -4
- package/template/apps/server/src/admin/routes.test.ts +29 -1
- package/template/apps/server/src/admin/routes.ts +20 -2
- package/template/apps/server/src/agent/client-session/completion.ts +1 -1
- package/template/apps/server/src/agent/client-session/manifest-admission.ts +1 -1
- package/template/apps/server/src/agent/client-session/request.ts +1 -1
- package/template/apps/server/src/agent/context-version-routes.ts +37 -13
- package/template/apps/server/src/agent/dsh-runtime-wire.test.ts +33 -0
- package/template/apps/server/src/agent/governance-runtime.ts +41 -0
- package/template/apps/server/src/agent/remote-runtime-response.ts +1 -1
- package/template/apps/server/src/agent/run-contracts.ts +1 -0
- package/template/apps/server/src/agent/run-definition-support.ts +9 -0
- package/template/apps/server/src/agent/run-facade.ts +1 -1
- package/template/apps/server/src/agent/run-input-verification.ts +1 -1
- package/template/apps/server/src/agent/run-routes.ts +1 -14
- package/template/apps/server/src/agent/run-start-preparation.ts +1 -1
- package/template/apps/server/src/agent/runtime-bootstrap-input.ts +2 -0
- package/template/apps/server/src/agent/runtime-bootstrap.ts +49 -157
- package/template/apps/server/src/agent/runtime-disabled-composition.ts +2 -1
- package/template/apps/server/src/agent/runtime-tool-composition.ts +2 -0
- package/template/apps/server/src/agent/session-invalidation/authorization-revocation.ts +54 -0
- package/template/apps/server/src/agent/session-runtime-composition.ts +1 -51
- package/template/apps/server/src/agent/unavailable-routes.ts +13 -2
- package/template/apps/server/src/agent/workflow-runtime-bootstrap.ts +9 -0
- package/template/apps/server/src/agent-skills/access.ts +88 -0
- package/template/apps/server/src/agent-skills/bootstrap.ts +49 -0
- package/template/apps/server/src/agent-skills/builtin-registration.ts +83 -0
- package/template/apps/server/src/agent-skills/builtins.ts +19 -0
- package/template/apps/server/src/agent-skills/bundle-zip.ts +163 -0
- package/template/apps/server/src/agent-skills/bundle.test.ts +79 -0
- package/template/apps/server/src/agent-skills/bundle.ts +133 -0
- package/template/apps/server/src/agent-skills/contracts.ts +46 -0
- package/template/apps/server/src/agent-skills/drizzle-repository.ts +125 -0
- package/template/apps/server/src/agent-skills/input.ts +29 -0
- package/template/apps/server/src/agent-skills/postgres.integration.test.ts +348 -0
- package/template/apps/server/src/agent-skills/read-routes.test.ts +116 -0
- package/template/apps/server/src/agent-skills/reader.ts +108 -0
- package/template/apps/server/src/agent-skills/repository.ts +105 -0
- package/template/apps/server/src/agent-skills/routes.ts +176 -0
- package/template/apps/server/src/agent-skills/service.test.ts +295 -0
- package/template/apps/server/src/agent-skills/service.ts +301 -0
- package/template/apps/server/src/agent-workflow/preset-registry.test.ts +137 -0
- package/template/apps/server/src/agent-workflow/preset-registry.ts +191 -0
- package/template/apps/server/src/agent-workflow/preset-routes.test.ts +94 -0
- package/template/apps/server/src/agent-workflow/preset-routes.ts +45 -0
- package/template/apps/server/src/agent-workflow/runtime-composition.ts +3 -0
- package/template/apps/server/src/agent-workflow/service.ts +17 -1
- package/template/apps/server/src/ai-artifact/media-resource-route.test.ts +134 -0
- package/template/apps/server/src/ai-artifact/routes.ts +1 -1
- package/template/apps/server/src/ai-artifact/runtime.ts +12 -0
- package/template/apps/server/src/ai-runtime-readiness/operation-port.test-support.ts +1 -1
- package/template/apps/server/src/ai-runtime-readiness/operation-port.ts +8 -0
- package/template/apps/server/src/ai-runtime-report/service.test.ts +10 -7
- package/template/apps/server/src/ai-runtime-report/service.ts +1 -1
- package/template/apps/server/src/ai-runtime-security/internal-token.ts +14 -0
- package/template/apps/server/src/app/agent-workflow-presets.ts +4 -0
- package/template/apps/server/src/app/antivirus-composition.test.ts +63 -0
- package/template/apps/server/src/app/antivirus-composition.ts +29 -0
- package/template/apps/server/src/app/dsh-skill-draft-audit.test.ts +195 -0
- package/template/apps/server/src/app/dsh-skill-draft-audit.ts +115 -0
- package/template/apps/server/src/app/dsh-workbench-audit.test.ts +71 -0
- package/template/apps/server/src/app/dsh-workbench-audit.ts +34 -0
- package/template/apps/server/src/app/dsh-workbench-handshake.test.ts +63 -0
- package/template/apps/server/src/app/dsh-workbench-handshake.ts +48 -0
- package/template/apps/server/src/app/dsh-workbench-http.test.ts +96 -0
- package/template/apps/server/src/app/dsh-workbench-lan-origin.test.ts +114 -0
- package/template/apps/server/src/app/dsh-workbench-launch.test.ts +70 -0
- package/template/apps/server/src/app/dsh-workbench-origin.test.ts +54 -0
- package/template/apps/server/src/app/dsh-workbench-proxy.ts +205 -0
- package/template/apps/server/src/app/dsh-workbench-session-conflict.test.ts +61 -0
- package/template/apps/server/src/app/dsh-workbench-session.ts +59 -0
- package/template/apps/server/src/app/dsh-workbench-socket-audit.test.ts +116 -0
- package/template/apps/server/src/app/dsh-workbench-socket.test.ts +246 -0
- package/template/apps/server/src/app/dsh-workbench-socket.ts +272 -0
- package/template/apps/server/src/app/dsh-workbench-test-support.ts +158 -0
- package/template/apps/server/src/app/dsh-workbench.test.ts +213 -0
- package/template/apps/server/src/app/dsh-workbench.ts +279 -0
- package/template/apps/server/src/app/workbench-public-origin.ts +16 -0
- package/template/apps/server/src/configuration/definition.ts +15 -11
- package/template/apps/server/src/data-governance/user-plaintext-routes.test.ts +3 -0
- package/template/apps/server/src/document/facade-support.ts +2 -2
- package/template/apps/server/src/document/facade.ts +2 -2
- package/template/apps/server/src/document/output-artifact-composition.ts +9 -5
- package/template/apps/server/src/document/output-artifact.test-support.ts +1 -1
- package/template/apps/server/src/embedding/facade.ts +1 -1
- package/template/apps/server/src/embedding/input.ts +1 -1
- package/template/apps/server/src/embedding/routes.ts +1 -1
- package/template/apps/server/src/http-app.ts +31 -0
- package/template/apps/server/src/index.ts +60 -60
- package/template/apps/server/src/license/routes.ts +4 -1
- package/template/apps/server/src/license/runtime-business-access.test.ts +261 -0
- package/template/apps/server/src/mcp/adapter.ts +1 -0
- package/template/apps/server/src/media-runtime/composition.ts +157 -0
- package/template/apps/server/src/media-runtime/media-only-composition.ts +44 -0
- package/template/apps/server/src/media-runtime/module-ai-port-factory.test.ts +69 -0
- package/template/apps/server/src/media-runtime/module-ai-port-factory.ts +72 -0
- package/template/apps/server/src/{agent → media-runtime}/runtime-readiness-sources.ts +14 -6
- package/template/apps/server/src/media-runtime/shared-composition.ts +104 -0
- package/template/apps/server/src/module-composition.test.ts +45 -0
- package/template/apps/server/src/module-composition.ts +57 -2
- package/template/apps/server/src/module-host/ai-operation-port.ts +97 -30
- package/template/apps/server/src/module-host/ai-operation-speech-normalize.test.ts +1 -1
- package/template/apps/server/src/module-host/http-runtime.ts +9 -3
- package/template/apps/server/src/module-host/static-route-authorization.test.ts +6 -3
- package/template/apps/server/src/module-host/storage-authorization-binding.test.ts +4 -0
- package/template/apps/server/src/module-runtime-validation.ts +2 -0
- package/template/apps/server/src/observability/bootstrap.ts +12 -0
- package/template/apps/server/src/observability/diagnostic-failure-recorder.ts +94 -0
- package/template/apps/server/src/observability/diagnostic-http-contract.test.ts +42 -0
- package/template/apps/server/src/observability/diagnostic-index.test.ts +89 -0
- package/template/apps/server/src/observability/diagnostic-index.ts +113 -0
- package/template/apps/server/src/observability/diagnostic-repository.ts +96 -0
- package/template/apps/server/src/platform-app-bootstrap.ts +42 -0
- package/template/apps/server/src/platform-http-runtime.ts +7 -1
- package/template/apps/server/src/runtime-development.test.ts +25 -0
- package/template/apps/server/src/runtime-development.ts +6 -44
- package/template/apps/server/src/runtime-feature.ts +5 -1
- package/template/apps/server/src/runtime.ts +3 -0
- package/template/apps/server/src/settings/drizzle-watermark-repository.ts +35 -4
- package/template/apps/server/src/settings/watermark-repository.ts +14 -0
- package/template/apps/server/src/settings/watermark-routes.test.ts +84 -2
- package/template/apps/server/src/settings/watermark-routes.ts +109 -0
- package/template/apps/server/src/settings/watermark-transfer.ts +79 -0
- package/template/apps/server/src/speech/facade-validation.ts +1 -1
- package/template/apps/server/src/speech/facade.ts +2 -2
- package/template/apps/server/src/startup-composition-validation.test.ts +32 -0
- package/template/apps/server/src/startup-finalization.ts +2 -0
- package/template/apps/server/src/startup-runtime.ts +77 -0
- package/template/apps/server/src/system/ai-runtime-build.ts +3 -0
- package/template/apps/server/src/system/ai-runtime-configuration.test.ts +36 -0
- package/template/apps/server/src/system/ai-runtime-configuration.ts +58 -0
- package/template/apps/server/src/system/diagnostic-routes.test.ts +123 -0
- package/template/apps/server/src/system/diagnostic-routes.ts +101 -0
- package/template/apps/server/src/system/environment-policy-reader.test.ts +74 -0
- package/template/apps/server/src/system/environment-policy-reader.ts +62 -0
- package/template/apps/server/src/system/feature-environment-assessment.test.ts +148 -0
- package/template/apps/server/src/system/feature-environment-assessment.ts +179 -0
- package/template/apps/server/src/system/host-diagnostics.test.ts +155 -0
- package/template/apps/server/src/system/host-diagnostics.ts +225 -0
- package/template/apps/server/src/system/menu-registry.test.ts +26 -0
- package/template/apps/server/src/system/menu-registry.ts +9 -7
- package/template/apps/server/src/system/operations.test.ts +5 -0
- package/template/apps/server/src/system/operations.ts +36 -12
- package/template/apps/server/src/system/role-authorization-postgres.integration.test.ts +181 -0
- package/template/apps/web/Dockerfile +15 -3
- package/template/apps/web/dev/dev-port.test.ts +6 -6
- package/template/apps/web/dev/dev-port.ts +1 -1
- package/template/apps/web/dev/start.ts +27 -11
- package/template/apps/web/dsh-workbench-location.ts +21 -0
- package/template/apps/web/dsh-workbench-proxy.test.ts +121 -0
- package/template/apps/web/dsh-workbench-proxy.ts +194 -0
- package/template/apps/web/index.html +1 -0
- package/template/apps/web/package.json +18 -16
- package/template/apps/web/runtime-server.test.ts +22 -1
- package/template/apps/web/runtime-server.ts +6 -0
- package/template/apps/web/server.ts +27 -6
- package/template/apps/web/src/App.vue +6 -3
- package/template/apps/web/src/assets/windy.svg +4 -0
- package/template/apps/web/src/components/auth/LoginForm.vue +2 -2
- package/template/apps/web/src/components/auth/PasswordChangeForm.vue +14 -3
- package/template/apps/web/src/components/common/FormDialog.vue +1 -1
- package/template/apps/web/src/components/license/LicenseFlow.webtest.ts +3 -0
- package/template/apps/web/src/components/license/LicenseMachineCodeQr.vue +99 -0
- package/template/apps/web/src/components/license/LicenseMachineCodeQr.webtest.ts +83 -0
- package/template/apps/web/src/components/license/LicensePairingCard.vue +1 -1
- package/template/apps/web/src/components/license/LicenseStatusCard.vue +14 -2
- package/template/apps/web/src/composables/useLoginFlow.ts +13 -1
- package/template/apps/web/src/composables/usePlatformSettings.ts +1 -1
- package/template/apps/web/src/composables/useWatermarkSettings.ts +1 -0
- package/template/apps/web/src/layout/AppSidebar.vue +5 -9
- package/template/apps/web/src/layout/AppSidebar.webtest.ts +4 -1
- package/template/apps/web/src/pages/auth/ChangePasswordPage.vue +67 -6
- package/template/apps/web/src/pages/auth/LoginPage.vue +3 -12
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationEditor.vue +30 -0
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationWorkbench.vue +25 -14
- package/template/apps/web/src/pages/configuration/components/TimeZoneSelect.vue +55 -0
- package/template/apps/web/src/pages/errors/PlatformErrorPage.vue +6 -0
- package/template/apps/web/src/pages/errors/PlatformErrorPage.webtest.ts +14 -1
- package/template/apps/web/src/pages/errors/error-page-extension.ts +1 -0
- package/template/apps/web/src/pages/profile/PersonalSettingsPage.vue +64 -11
- package/template/apps/web/src/pages/profile/PersonalSettingsPage.webtest.ts +21 -1
- package/template/apps/web/src/pages/settings/BrandingSettingsSection.vue +7 -18
- package/template/apps/web/src/pages/settings/BrandingSettingsSection.webtest.ts +9 -4
- package/template/apps/web/src/pages/settings/GlobalSettingsPage.vue +51 -6
- package/template/apps/web/src/pages/settings/GlobalSettingsPage.webtest.ts +19 -3
- package/template/apps/web/src/pages/settings/WatermarkSettingsSection.vue +1 -0
- package/template/apps/web/src/pages/settings/WatermarkYamlTransfer.vue +211 -0
- package/template/apps/web/src/pages/system/AgentNativePage.vue +44 -0
- package/template/apps/web/src/pages/system/AgentWorkflowPage.vue +20 -7
- package/template/apps/web/src/pages/system/DiagnosticLookupPage.vue +71 -0
- package/template/apps/web/src/pages/system/DiagnosticLookupPage.webtest.ts +102 -0
- package/template/apps/web/src/pages/system/SystemAgentSkillsPage.vue +88 -0
- package/template/apps/web/src/pages/system/SystemOperationsPage.vue +23 -0
- package/template/apps/web/src/pages/system/components/DiagnosticLogList.vue +120 -0
- package/template/apps/web/src/pages/system/components/DiagnosticRecordDetails.vue +52 -0
- package/template/apps/web/src/pages/system/components/OperationEnvironmentPanel.vue +237 -0
- package/template/apps/web/src/pages/system/components/OperationFeatureAssessmentPanel.vue +131 -0
- package/template/apps/web/src/pages/system/components/PagedSelectionList.vue +31 -24
- package/template/apps/web/src/pages/system/components/SystemResourceActions.vue +2 -1
- package/template/apps/web/src/pages/system/components/SystemResourceEditor.vue +11 -2
- package/template/apps/web/src/pages/system/components/SystemResourcePage.vue +1 -0
- package/template/apps/web/src/pages/system/components/SystemResourcePage.webtest.ts +6 -2
- package/template/apps/web/src/pages/system/components/agent-skills/AgentSkillDetailDialog.vue +166 -0
- package/template/apps/web/src/pages/system/components/agent-skills/AgentSkillGovernanceActionDialog.vue +51 -0
- package/template/apps/web/src/pages/system/components/agent-skills/AgentSkillImportDialog.vue +329 -0
- package/template/apps/web/src/pages/system/components/agent-skills/AgentSkillImportDialog.webtest.ts +96 -0
- package/template/apps/web/src/pages/system/components/agent-skills/AgentSkillsTable.vue +69 -0
- package/template/apps/web/src/pages/system/components/agent-workbench/SessionReplayTimeline.vue +18 -9
- package/template/apps/web/src/pages/system/components/agent-workbench/TestRunComposer.vue +66 -34
- package/template/apps/web/src/pages/system/components/agent-workbench/ToolCatalogPanel.vue +48 -33
- package/template/apps/web/src/pages/system/components/agent-workbench/ToolCatalogPanel.webtest.ts +9 -2
- package/template/apps/web/src/pages/system/components/agent-workbench/ToolRuleDetail.vue +23 -16
- package/template/apps/web/src/pages/system/components/agent-workflow/WorkflowPresetCatalog.vue +82 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/WorkflowPresetCatalog.webtest.ts +57 -0
- package/template/apps/web/src/pages/system/components/dictionary-bulk/DictionaryBulkJobDetail.vue +10 -7
- package/template/apps/web/src/pages/system/components/user-account/RolePermissionSummary.vue +81 -57
- package/template/apps/web/src/pages/system/components/user-account/UserRoleSelector.vue +6 -4
- package/template/apps/web/src/pages/system/components/user-account/UserRoleSelector.webtest.ts +20 -4
- package/template/apps/web/src/pages/system/composables/useAgentSkillsGovernance.ts +105 -0
- package/template/apps/web/src/pages/system/composables/useAgentWorkflowPresets.ts +44 -0
- package/template/apps/web/src/pages/system/composables/useDiagnosticLookup.ts +64 -0
- package/template/apps/web/src/pages/system/resource-config.ts +9 -0
- package/template/apps/web/src/pages/work-orders/WorkOrderListPage.vue +1 -1
- package/template/apps/web/src/router/disabled-feature-loading.webtest.ts +78 -0
- package/template/apps/web/src/router/error-navigation.ts +3 -1
- package/template/apps/web/src/router/error-navigation.webtest.ts +14 -2
- package/template/apps/web/src/router/index.ts +11 -55
- package/template/apps/web/src/router/manifest-routes.ts +2 -3
- package/template/apps/web/src/router/platform-admin-pages.ts +38 -0
- package/template/apps/web/src/router/platform-admin-route-bindings.ts +12 -4
- package/template/apps/web/src/services/agent-skills-api.ts +55 -0
- package/template/apps/web/src/services/agent-workflow-api.ts +12 -0
- package/template/apps/web/src/services/diagnostics-api.ts +24 -0
- package/template/apps/web/src/services/http.ts +18 -0
- package/template/apps/web/src/services/http.webtest.ts +51 -0
- package/template/apps/web/src/services/operations-api.ts +4 -0
- package/template/apps/web/src/services/platform-settings-api.ts +35 -1
- package/template/apps/web/vite.config.ts +47 -2
- package/template/deploy/dsh/README.md +5 -0
- package/template/deploy/dsh/documents/README.md +9 -0
- package/template/deploy/dsh/documents/requirements.in +6 -0
- package/template/deploy/dsh/documents/requirements.lock +72 -0
- package/template/deploy/environment/windy.environment.example.yaml +53 -0
- package/template/docker-compose.yml +27 -11
- package/template/docs/adr/0004-embedded-dsh-runtime.md +9 -0
- package/template/docs/architecture/agent-admin-workbench-implementation.md +73 -0
- package/template/docs/architecture/agent-admin-workbench-plan.md +41 -0
- package/template/docs/architecture/agent-harness.md +2 -0
- package/template/docs/architecture/agent-runtime-compatibility.md +2 -0
- package/template/docs/architecture/agent-workflow.md +8 -0
- package/template/docs/architecture/durable-jobs.md +17 -0
- package/template/docs/architecture/embedded-dsh-integration.md +44 -0
- package/template/docs/development/dsh-plugins.md +55 -0
- package/template/docs/development/performance-engineering.md +24 -0
- package/template/docs/operations/admin-settings-yaml.md +29 -0
- package/template/docs/operations/dsh-agent-migration.md +98 -0
- package/template/docs/operations/environment-capabilities.md +185 -0
- package/template/docs/platform/agent-production-store.md +5 -78
- package/template/docs/platform/agent-runtime-observability.md +2 -0
- package/template/docs/platform/agent-runtime.md +2 -0
- package/template/docs/platform/agent-skills.md +25 -0
- package/template/docs/platform/module-configuration.md +18 -3
- package/template/docs/platform/platform-authentication.md +1 -1
- package/template/package.json +13 -10
- package/template/packages/config/package.json +2 -2
- package/template/packages/config/src/definition.ts +14 -4
- package/template/packages/config/src/environment-loader.ts +27 -3
- package/template/packages/config/src/platform-ai-runtime.test.ts +94 -0
- package/template/packages/config/src/platform.ts +5 -2
- package/template/packages/database/drizzle/0064_dsh_skills_diagnostics.sql +42 -0
- package/template/packages/database/drizzle/0065_durable_job_lease_snapshot_lookup.sql +1 -0
- package/template/packages/database/drizzle/0066_agent_source_sequence_bigint.sql +3 -0
- package/template/packages/database/drizzle/0067_media_runtime_access.sql +46 -0
- package/template/packages/database/drizzle/meta/0064_snapshot.json +15349 -0
- package/template/packages/database/drizzle/meta/0065_snapshot.json +15370 -0
- package/template/packages/database/drizzle/meta/0066_snapshot.json +15370 -0
- package/template/packages/database/drizzle/meta/0067_snapshot.json +15370 -0
- package/template/packages/database/drizzle/meta/_journal.json +28 -0
- package/template/packages/database/package.json +4 -4
- package/template/packages/database/src/schema/agent-session.ts +4 -3
- package/template/packages/database/src/schema/agent-skills.ts +65 -0
- package/template/packages/database/src/schema/diagnostics.ts +27 -0
- package/template/packages/database/src/schema/durable-jobs.ts +4 -0
- package/template/packages/database/src/schema/index.ts +10 -0
- package/template/packages/database/src/schema-durable-recovery.test.ts +21 -1
- package/template/packages/database/src/schema-source-sequence.test.ts +24 -0
- package/template/packages/example-work-order/package.json +2 -2
- package/template/packages/modules/package.json +1 -1
- package/template/packages/modules/src/admin-ui-boundary.test.ts +33 -0
- package/template/packages/modules/src/composition.ts +11 -28
- package/template/packages/modules/src/manifest.ts +2 -0
- package/template/packages/modules/src/menu-composition.ts +24 -0
- package/template/packages/modules/src/system-admin-routes.ts +26 -2
- package/template/packages/modules/src/system-admin-ui-catalog.ts +23 -11
- package/template/packages/modules/src/system-agent-admin-bindings.ts +2 -0
- package/template/packages/modules/src/system-agent-admin-menus.ts +20 -0
- package/template/packages/modules/src/system-agent-audit-actions.ts +3 -0
- package/template/packages/modules/src/system-agent-dsh.ts +119 -0
- package/template/packages/modules/src/system-ai-api-bindings.ts +0 -16
- package/template/packages/modules/src/system-api-control-plane.ts +9 -1
- package/template/packages/modules/src/system-api-permissions.ts +16 -0
- package/template/packages/modules/src/system-api-watermark.ts +21 -0
- package/template/packages/modules/src/system-audit-actions.ts +14 -1
- package/template/packages/modules/src/system-features.ts +25 -2
- package/template/packages/modules/src/system-media-api-bindings.ts +97 -0
- package/template/packages/modules/src/system-module-audit-selection.ts +27 -0
- package/template/packages/modules/src/system-module-catalog.test.ts +13 -6
- package/template/packages/modules/src/system-module-catalog.ts +12 -267
- package/template/packages/modules/src/system-module-definitions.ts +260 -0
- package/template/packages/modules/src/system-modules-access.test.ts +2 -0
- package/template/packages/modules/src/system-modules.test.ts +7 -1
- package/template/packages/modules/src/system-modules.ts +39 -16
- package/template/packages/modules/src/system-permissions.ts +22 -0
- package/template/packages/server-sdk/package.json +2 -2
- package/template/packages/shared/index.ts +15 -0
- package/template/packages/shared/package.json +1 -1
- package/template/packages/shared/src/agent-skills.ts +68 -0
- package/template/packages/shared/src/agent-workflow-presets.ts +26 -0
- package/template/packages/shared/src/diagnostics.ts +13 -0
- package/template/packages/shared/src/environment-assessment.ts +68 -0
- package/template/packages/shared/src/environment-policy.ts +205 -0
- package/template/packages/shared/src/license-console-capabilities.ts +7 -0
- package/template/packages/shared/src/license.ts +1 -0
- package/template/packages/shared/src/module-configuration.ts +2 -1
- package/template/packages/shared/src/rbac.ts +1 -0
- package/template/scripts/operations/collect-device-info.py +230 -0
- package/template/apps/agent-server/install-python-dependencies.sh +0 -92
- package/template/apps/agent-server/pyproject.toml +0 -51
- package/template/apps/agent-server/src/southwind_agent_server/__init__.py +0 -5
- package/template/apps/agent-server/src/southwind_agent_server/app.py +0 -344
- package/template/apps/agent-server/src/southwind_agent_server/approval_resolution.py +0 -30
- package/template/apps/agent-server/src/southwind_agent_server/artifact_input.py +0 -153
- package/template/apps/agent-server/src/southwind_agent_server/asgi.py +0 -8
- package/template/apps/agent-server/src/southwind_agent_server/attempt_context.py +0 -199
- package/template/apps/agent-server/src/southwind_agent_server/attempt_context_projection.py +0 -203
- package/template/apps/agent-server/src/southwind_agent_server/client_completion_contracts.py +0 -61
- package/template/apps/agent-server/src/southwind_agent_server/client_completion_governance.py +0 -82
- package/template/apps/agent-server/src/southwind_agent_server/client_completion_routes.py +0 -121
- package/template/apps/agent-server/src/southwind_agent_server/client_completion_runtime.py +0 -158
- package/template/apps/agent-server/src/southwind_agent_server/config.py +0 -267
- package/template/apps/agent-server/src/southwind_agent_server/context_message_digest.py +0 -24
- package/template/apps/agent-server/src/southwind_agent_server/context_version_contracts.py +0 -71
- package/template/apps/agent-server/src/southwind_agent_server/context_version_port.py +0 -307
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +0 -297
- package/template/apps/agent-server/src/southwind_agent_server/deterministic.py +0 -63
- package/template/apps/agent-server/src/southwind_agent_server/engine.py +0 -134
- package/template/apps/agent-server/src/southwind_agent_server/engine_capacity.py +0 -31
- package/template/apps/agent-server/src/southwind_agent_server/engine_identity.py +0 -2
- package/template/apps/agent-server/src/southwind_agent_server/fingerprint.py +0 -61
- package/template/apps/agent-server/src/southwind_agent_server/health_routes.py +0 -93
- package/template/apps/agent-server/src/southwind_agent_server/http_helpers.py +0 -62
- package/template/apps/agent-server/src/southwind_agent_server/lease.py +0 -15
- package/template/apps/agent-server/src/southwind_agent_server/multimodal.py +0 -76
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +0 -329
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine_validation.py +0 -165
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +0 -345
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_insert.py +0 -37
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_queries.py +0 -235
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_replay.py +0 -44
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_status.py +0 -83
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_store.py +0 -336
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_summary.py +0 -304
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store.py +0 -335
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store_backend.py +0 -333
- package/template/apps/agent-server/src/southwind_agent_server/provider_audit.py +0 -144
- package/template/apps/agent-server/src/southwind_agent_server/provider_governance.py +0 -309
- package/template/apps/agent-server/src/southwind_agent_server/provider_output_guidance.py +0 -34
- package/template/apps/agent-server/src/southwind_agent_server/readiness_pin.py +0 -37
- package/template/apps/agent-server/src/southwind_agent_server/report_lifecycle.py +0 -218
- package/template/apps/agent-server/src/southwind_agent_server/report_metrics.py +0 -149
- package/template/apps/agent-server/src/southwind_agent_server/report_presenter.py +0 -300
- package/template/apps/agent-server/src/southwind_agent_server/report_routes.py +0 -132
- package/template/apps/agent-server/src/southwind_agent_server/report_store.py +0 -298
- package/template/apps/agent-server/src/southwind_agent_server/report_store_protocol.py +0 -75
- package/template/apps/agent-server/src/southwind_agent_server/report_types.py +0 -118
- package/template/apps/agent-server/src/southwind_agent_server/run_admission.py +0 -64
- package/template/apps/agent-server/src/southwind_agent_server/run_capacity.py +0 -59
- package/template/apps/agent-server/src/southwind_agent_server/runtime_budget.py +0 -74
- package/template/apps/agent-server/src/southwind_agent_server/runtime_compatibility.py +0 -89
- package/template/apps/agent-server/src/southwind_agent_server/runtime_factory.py +0 -105
- package/template/apps/agent-server/src/southwind_agent_server/runtime_logging.py +0 -57
- package/template/apps/agent-server/src/southwind_agent_server/service.py +0 -325
- package/template/apps/agent-server/src/southwind_agent_server/service_control.py +0 -64
- package/template/apps/agent-server/src/southwind_agent_server/service_errors.py +0 -4
- package/template/apps/agent-server/src/southwind_agent_server/service_execution.py +0 -34
- package/template/apps/agent-server/src/southwind_agent_server/service_tasks.py +0 -34
- package/template/apps/agent-server/src/southwind_agent_server/signal_events.py +0 -53
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_catalog.py +0 -118
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_errors.py +0 -2
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_schema.py +0 -73
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_serialization.py +0 -16
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_store.py +0 -350
- package/template/apps/agent-server/src/southwind_agent_server/sse.py +0 -41
- package/template/apps/agent-server/src/southwind_agent_server/store.py +0 -255
- package/template/apps/agent-server/src/southwind_agent_server/store_cipher.py +0 -40
- package/template/apps/agent-server/src/southwind_agent_server/structured_logging.py +0 -145
- package/template/apps/agent-server/src/southwind_agent_server/telemetry.py +0 -93
- package/template/apps/agent-server/src/southwind_agent_server/tool_host.py +0 -152
- package/template/apps/agent-server/src/southwind_agent_server/trajectory.py +0 -137
- package/template/apps/agent-server/src/southwind_agent_server/unavailable_engine.py +0 -58
- package/template/apps/agent-server/src/southwind_agent_server/vision_probe.py +0 -87
- package/template/apps/agent-server/src/southwind_agent_server/vision_requirement.py +0 -28
- package/template/apps/agent-server/src/southwind_agent_server/vlm_readiness.py +0 -247
- package/template/apps/agent-server/tests/__init__.py +0 -1
- package/template/apps/agent-server/tests/openai_provider_test_support.py +0 -131
- package/template/apps/agent-server/tests/test_api.py +0 -305
- package/template/apps/agent-server/tests/test_artifact_input.py +0 -110
- package/template/apps/agent-server/tests/test_client_completion.py +0 -230
- package/template/apps/agent-server/tests/test_config.py +0 -106
- package/template/apps/agent-server/tests/test_fingerprint.py +0 -10
- package/template/apps/agent-server/tests/test_multimodal.py +0 -81
- package/template/apps/agent-server/tests/test_openai_provider.py +0 -320
- package/template/apps/agent-server/tests/test_postgres_report_status.py +0 -59
- package/template/apps/agent-server/tests/test_postgres_report_summary.py +0 -298
- package/template/apps/agent-server/tests/test_postgres_store.py +0 -135
- package/template/apps/agent-server/tests/test_provider_attempt_reporting.py +0 -140
- package/template/apps/agent-server/tests/test_provider_governance.py +0 -276
- package/template/apps/agent-server/tests/test_report_attempt_lifecycle.py +0 -126
- package/template/apps/agent-server/tests/test_report_resilience.py +0 -183
- package/template/apps/agent-server/tests/test_report_routes.py +0 -143
- package/template/apps/agent-server/tests/test_report_store.py +0 -347
- package/template/apps/agent-server/tests/test_report_summary_parity.py +0 -116
- package/template/apps/agent-server/tests/test_report_terminal_sync.py +0 -177
- package/template/apps/agent-server/tests/test_run_capacity.py +0 -112
- package/template/apps/agent-server/tests/test_run_operational_logging.py +0 -114
- package/template/apps/agent-server/tests/test_runtime_compatibility.py +0 -119
- package/template/apps/agent-server/tests/test_runtime_factory_readiness.py +0 -52
- package/template/apps/agent-server/tests/test_sqlite_store.py +0 -182
- package/template/apps/agent-server/tests/test_structured_logging.py +0 -142
- package/template/apps/agent-server/tests/test_telemetry.py +0 -25
- package/template/apps/agent-server/tests/test_tool_approval.py +0 -28
- package/template/apps/agent-server/tests/test_tool_structured_output.py +0 -347
- package/template/apps/agent-server/tests/test_trajectory.py +0 -91
- package/template/apps/agent-server/tests/test_vision_readiness_enforcement.py +0 -72
- package/template/apps/agent-server/tests/test_vlm_readiness.py +0 -106
- package/template/apps/agent-server/uv.lock +0 -831
- package/template/apps/server/src/agent/module-ai-port-factory.ts +0 -41
- /package/template/apps/server/src/{agent → ai-runtime-security}/execution-grants.ts +0 -0
- /package/template/apps/server/src/{agent → ai-runtime-security}/idempotency-key.test.ts +0 -0
- /package/template/apps/server/src/{agent → ai-runtime-security}/idempotency-key.ts +0 -0
- /package/template/apps/server/src/{agent → ai-runtime-security}/provider-input-governance.test.ts +0 -0
- /package/template/apps/server/src/{agent → ai-runtime-security}/provider-input-governance.ts +0 -0
- /package/template/apps/server/src/{agent → media-runtime}/required-environment.ts +0 -0
- /package/template/apps/server/src/{agent → media-runtime}/runtime-readiness-sources.test.ts +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { GenerateOptions } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import type { RuntimeConfig } from "./config.js";
|
|
3
|
+
import type { RunRequest } from "./contracts.js";
|
|
4
|
+
import { SafeError } from "./contracts.js";
|
|
5
|
+
import type { RuntimeStore } from "./store.js";
|
|
6
|
+
import type { ExecutionBudget } from "./model-plugin.js";
|
|
7
|
+
import { HostContextPlugin } from "./context-plugin.js";
|
|
8
|
+
import { governProvider } from "./governance.js";
|
|
9
|
+
import { wireMessage } from "./model-wire.js";
|
|
10
|
+
import { admitProviderContext } from "./context-budget.js";
|
|
11
|
+
export async function prepareModelPayload(
|
|
12
|
+
config: RuntimeConfig,
|
|
13
|
+
request: RunRequest,
|
|
14
|
+
runId: string,
|
|
15
|
+
store: RuntimeStore,
|
|
16
|
+
budget: ExecutionBudget,
|
|
17
|
+
options: GenerateOptions,
|
|
18
|
+
images: ReadonlyMap<string, string>,
|
|
19
|
+
remainingTokens: number,
|
|
20
|
+
) {
|
|
21
|
+
const context = new HostContextPlugin(
|
|
22
|
+
config,
|
|
23
|
+
request,
|
|
24
|
+
runId,
|
|
25
|
+
`${runId}_attempt_${budget.attempts}`,
|
|
26
|
+
options.signal,
|
|
27
|
+
);
|
|
28
|
+
const prepared = await context.prepare(
|
|
29
|
+
options.messages.map((message) => wireMessage(message, images)),
|
|
30
|
+
);
|
|
31
|
+
try {
|
|
32
|
+
const governed = governProvider(
|
|
33
|
+
prepared.messages,
|
|
34
|
+
(options.tools ?? []).map((tool) => ({
|
|
35
|
+
type: "function",
|
|
36
|
+
function: {
|
|
37
|
+
name: tool.name,
|
|
38
|
+
description: tool.description,
|
|
39
|
+
parameters: tool.parameters,
|
|
40
|
+
},
|
|
41
|
+
})),
|
|
42
|
+
request.outputSchema,
|
|
43
|
+
request.providerDataPolicy,
|
|
44
|
+
store,
|
|
45
|
+
{
|
|
46
|
+
runId,
|
|
47
|
+
operationKey: request.operationKey,
|
|
48
|
+
deploymentKey: config.deploymentKey,
|
|
49
|
+
attempt: budget.attempts,
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
const payload: Record<string, unknown> = {
|
|
53
|
+
model: config.model,
|
|
54
|
+
messages: governed.messages,
|
|
55
|
+
stream: true,
|
|
56
|
+
stream_options: { include_usage: true },
|
|
57
|
+
parallel_tool_calls: false,
|
|
58
|
+
max_tokens: Math.min(
|
|
59
|
+
options.maxTokens ?? config.maxOutputTokens,
|
|
60
|
+
config.maxOutputTokens,
|
|
61
|
+
remainingTokens,
|
|
62
|
+
),
|
|
63
|
+
...config.generation,
|
|
64
|
+
};
|
|
65
|
+
if (governed.tools.length) payload.tools = governed.tools;
|
|
66
|
+
// Qwen's serving template uses either native tools or response_format.
|
|
67
|
+
// With tools, the authorized schema remains in DSH's governed system prompt
|
|
68
|
+
// and final output is still validated by the same local JSON Schema gate.
|
|
69
|
+
if (governed.schema && !governed.tools.length)
|
|
70
|
+
payload.response_format =
|
|
71
|
+
config.structuredOutputMode === "json_object"
|
|
72
|
+
? { type: "json_object" }
|
|
73
|
+
: {
|
|
74
|
+
type: "json_schema",
|
|
75
|
+
json_schema: {
|
|
76
|
+
name: "operation_result",
|
|
77
|
+
strict: true,
|
|
78
|
+
schema: governed.schema,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
const inputTokens = await admitProviderContext(
|
|
82
|
+
config,
|
|
83
|
+
payload,
|
|
84
|
+
options.signal,
|
|
85
|
+
);
|
|
86
|
+
if (
|
|
87
|
+
request.limits.maxInputTokens &&
|
|
88
|
+
budget.inputTokens + inputTokens > request.limits.maxInputTokens
|
|
89
|
+
)
|
|
90
|
+
throw new SafeError("BUDGET_EXCEEDED", "累计输入 token 预算已耗尽");
|
|
91
|
+
await context.commit(prepared.preparation, governed.messages, payload);
|
|
92
|
+
return { payload, estimatedInputTokens: inputTokens };
|
|
93
|
+
} catch (error) {
|
|
94
|
+
await context.abort(prepared.preparation);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ToolCallId,
|
|
3
|
+
type GenerateOptions,
|
|
4
|
+
type StreamChunk,
|
|
5
|
+
type ContentBlock,
|
|
6
|
+
} from "@deepseek-ai/dsh-llm";
|
|
7
|
+
import { prepareModelPayload } from "./model-payload.js";
|
|
8
|
+
import { FixedRouteAdapter } from "./model-route.js";
|
|
9
|
+
import { parseUsage } from "./model-usage.js";
|
|
10
|
+
import { SafeError, type RunRequest } from "./contracts.js";
|
|
11
|
+
import type { RuntimeConfig } from "./config.js";
|
|
12
|
+
import { sseJson } from "./governance.js";
|
|
13
|
+
import type { RuntimeStore } from "./store.js";
|
|
14
|
+
|
|
15
|
+
export interface ExecutionBudget {
|
|
16
|
+
attempts: number;
|
|
17
|
+
toolCalls: number;
|
|
18
|
+
inputTokens: number;
|
|
19
|
+
outputTokens: number;
|
|
20
|
+
outputBytes?: number;
|
|
21
|
+
failure?: SafeError;
|
|
22
|
+
}
|
|
23
|
+
export class GovernedModelAdapter extends FixedRouteAdapter {
|
|
24
|
+
constructor(
|
|
25
|
+
config: RuntimeConfig,
|
|
26
|
+
private readonly request: RunRequest,
|
|
27
|
+
private readonly runId: string,
|
|
28
|
+
private readonly store: RuntimeStore,
|
|
29
|
+
private readonly budget: ExecutionBudget,
|
|
30
|
+
private readonly images: ReadonlyMap<string, string> = new Map(),
|
|
31
|
+
) {
|
|
32
|
+
super(config);
|
|
33
|
+
}
|
|
34
|
+
override async *stream(
|
|
35
|
+
options: GenerateOptions,
|
|
36
|
+
): AsyncGenerator<StreamChunk> {
|
|
37
|
+
const sequence = this.budget.attempts + 1,
|
|
38
|
+
started = Date.now();
|
|
39
|
+
let firstTokenLatencyMs: number | null = null,
|
|
40
|
+
usage: Record<string, unknown> = {},
|
|
41
|
+
outcome = "completed";
|
|
42
|
+
this.store.startAttempt(
|
|
43
|
+
this.runId,
|
|
44
|
+
sequence,
|
|
45
|
+
this.config.deploymentKey,
|
|
46
|
+
this.config.model,
|
|
47
|
+
);
|
|
48
|
+
const signal = AbortSignal.any([
|
|
49
|
+
...(options.signal ? [options.signal] : []),
|
|
50
|
+
AbortSignal.timeout(this.config.requestTimeoutMs),
|
|
51
|
+
]);
|
|
52
|
+
try {
|
|
53
|
+
for await (const chunk of this.generate({ ...options, signal })) {
|
|
54
|
+
if (
|
|
55
|
+
(chunk.type === "text-delta" || chunk.type === "tool-call-delta") &&
|
|
56
|
+
firstTokenLatencyMs === null
|
|
57
|
+
)
|
|
58
|
+
firstTokenLatencyMs = Date.now() - started;
|
|
59
|
+
if (chunk.type === "usage")
|
|
60
|
+
usage = {
|
|
61
|
+
...chunk.usage,
|
|
62
|
+
inputTokens:
|
|
63
|
+
chunk.usage.inputTokens + (chunk.usage.cacheReadTokens ?? 0),
|
|
64
|
+
cachedInputTokens: chunk.usage.cacheReadTokens ?? null,
|
|
65
|
+
cacheStatus:
|
|
66
|
+
chunk.usage.cacheReadTokens === undefined
|
|
67
|
+
? "unknown"
|
|
68
|
+
: chunk.usage.cacheReadTokens > 0
|
|
69
|
+
? "hit"
|
|
70
|
+
: "miss",
|
|
71
|
+
usageSource: "provider-reported",
|
|
72
|
+
};
|
|
73
|
+
yield chunk;
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
outcome = options.signal?.aborted ? "cancelled" : "failed";
|
|
77
|
+
this.budget.failure =
|
|
78
|
+
error instanceof SafeError
|
|
79
|
+
? error
|
|
80
|
+
: new SafeError(
|
|
81
|
+
"PROVIDER_UNAVAILABLE",
|
|
82
|
+
"模型服务暂不可用",
|
|
83
|
+
true,
|
|
84
|
+
503,
|
|
85
|
+
);
|
|
86
|
+
throw this.budget.failure;
|
|
87
|
+
} finally {
|
|
88
|
+
this.store.finishAttempt(this.runId, sequence, {
|
|
89
|
+
outcome,
|
|
90
|
+
firstTokenLatencyMs,
|
|
91
|
+
...usage,
|
|
92
|
+
safeErrorCode: this.budget.failure?.code ?? null,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
private async *generate(
|
|
97
|
+
options: GenerateOptions,
|
|
98
|
+
): AsyncGenerator<StreamChunk> {
|
|
99
|
+
const { config, request, budget } = this;
|
|
100
|
+
if (
|
|
101
|
+
++budget.attempts >
|
|
102
|
+
Math.min(
|
|
103
|
+
config.maxAttempts,
|
|
104
|
+
request.limits.maxModelAttempts ?? config.maxAttempts,
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
throw new SafeError("BUDGET_EXCEEDED", "模型调用次数达到上限");
|
|
108
|
+
if (
|
|
109
|
+
request.providerEgress.mode !== "configured-endpoint" ||
|
|
110
|
+
request.providerEgress.deploymentKey !== config.deploymentKey
|
|
111
|
+
)
|
|
112
|
+
throw new SafeError("FORBIDDEN", "模型出网未获授权", false, 403);
|
|
113
|
+
if (
|
|
114
|
+
request.modelPin &&
|
|
115
|
+
(request.modelPin.model !== config.model ||
|
|
116
|
+
request.modelPin.deploymentKey !== config.deploymentKey)
|
|
117
|
+
)
|
|
118
|
+
throw new SafeError("MODEL_ROUTE_UNAVAILABLE", "模型路由已发生变化");
|
|
119
|
+
const remainingTokens =
|
|
120
|
+
(request.limits.maxOutputTokens ??
|
|
121
|
+
config.maxOutputTokens * config.maxAttempts) - budget.outputTokens;
|
|
122
|
+
if (remainingTokens <= 0)
|
|
123
|
+
throw new SafeError("BUDGET_EXCEEDED", "输出 token 预算已耗尽");
|
|
124
|
+
const prepared = await prepareModelPayload(
|
|
125
|
+
config,
|
|
126
|
+
request,
|
|
127
|
+
this.runId,
|
|
128
|
+
this.store,
|
|
129
|
+
budget,
|
|
130
|
+
options,
|
|
131
|
+
this.images,
|
|
132
|
+
remainingTokens,
|
|
133
|
+
);
|
|
134
|
+
const payload = prepared.payload;
|
|
135
|
+
const response = await fetch(`${config.baseUrl}/chat/completions`, {
|
|
136
|
+
method: "POST",
|
|
137
|
+
signal: options.signal,
|
|
138
|
+
headers: {
|
|
139
|
+
"content-type": "application/json",
|
|
140
|
+
...(config.apiKey ? { authorization: `Bearer ${config.apiKey}` } : {}),
|
|
141
|
+
"X-DSH-Session-Id": this.runId,
|
|
142
|
+
},
|
|
143
|
+
body: JSON.stringify(payload),
|
|
144
|
+
redirect: "error",
|
|
145
|
+
});
|
|
146
|
+
if (!response.ok) {
|
|
147
|
+
await response.body?.cancel();
|
|
148
|
+
throw new SafeError(
|
|
149
|
+
response.status === 429 ? "RATE_LIMITED" : "PROVIDER_UNAVAILABLE",
|
|
150
|
+
"模型服务请求失败",
|
|
151
|
+
response.status === 429 || response.status >= 500,
|
|
152
|
+
503,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const blocks = new Map<
|
|
156
|
+
number,
|
|
157
|
+
{
|
|
158
|
+
index: number;
|
|
159
|
+
type: "text" | "reasoning" | "tool-call";
|
|
160
|
+
text: string;
|
|
161
|
+
id: string;
|
|
162
|
+
name: string;
|
|
163
|
+
}
|
|
164
|
+
>();
|
|
165
|
+
let finish = "",
|
|
166
|
+
usageSeen = false,
|
|
167
|
+
outputBytes = 0;
|
|
168
|
+
const blockFor = (
|
|
169
|
+
key: number,
|
|
170
|
+
type: "text" | "reasoning" | "tool-call",
|
|
171
|
+
) => {
|
|
172
|
+
let block = blocks.get(key);
|
|
173
|
+
if (!block) {
|
|
174
|
+
block = { index: blocks.size, type, text: "", id: "", name: "" };
|
|
175
|
+
blocks.set(key, block);
|
|
176
|
+
return { block, fresh: true };
|
|
177
|
+
}
|
|
178
|
+
return { block, fresh: false };
|
|
179
|
+
};
|
|
180
|
+
for await (const chunk of sseJson(
|
|
181
|
+
response,
|
|
182
|
+
Math.min(config.maxResponseBytes, request.limits.maxOutputBytes * 4),
|
|
183
|
+
options.signal,
|
|
184
|
+
)) {
|
|
185
|
+
const usage = chunk.usage as Record<string, unknown> | undefined;
|
|
186
|
+
if (
|
|
187
|
+
usage &&
|
|
188
|
+
Number.isSafeInteger(usage.prompt_tokens) &&
|
|
189
|
+
Number.isSafeInteger(usage.completion_tokens)
|
|
190
|
+
) {
|
|
191
|
+
const inputTokens = Number(usage.prompt_tokens),
|
|
192
|
+
outputTokens = Number(usage.completion_tokens);
|
|
193
|
+
if (inputTokens < 0 || outputTokens < 0 || usageSeen)
|
|
194
|
+
throw new SafeError("PROVIDER_UNAVAILABLE", "模型计量无效");
|
|
195
|
+
budget.inputTokens += inputTokens;
|
|
196
|
+
budget.outputTokens += outputTokens;
|
|
197
|
+
usageSeen = true;
|
|
198
|
+
const value = parseUsage(usage);
|
|
199
|
+
this.store.event(this.runId, "usage.reported", {
|
|
200
|
+
attemptSequence: budget.attempts,
|
|
201
|
+
usage: value.canonical,
|
|
202
|
+
});
|
|
203
|
+
yield { type: "usage", usage: value.dsh };
|
|
204
|
+
}
|
|
205
|
+
const choices = chunk.choices;
|
|
206
|
+
if (!Array.isArray(choices) || !choices.length) continue;
|
|
207
|
+
const choice = choices[0] as Record<string, unknown>;
|
|
208
|
+
if (typeof choice.finish_reason === "string")
|
|
209
|
+
finish = choice.finish_reason;
|
|
210
|
+
const delta = choice.delta as Record<string, unknown> | undefined;
|
|
211
|
+
if (!delta) continue;
|
|
212
|
+
for (const [field, key, type] of [
|
|
213
|
+
["content", -1, "text"],
|
|
214
|
+
["reasoning_content", -2, "reasoning"],
|
|
215
|
+
] as const) {
|
|
216
|
+
const text = delta[field];
|
|
217
|
+
if (typeof text !== "string" || !text) continue;
|
|
218
|
+
outputBytes += Buffer.byteLength(text);
|
|
219
|
+
budget.outputBytes =
|
|
220
|
+
(budget.outputBytes ?? 0) + Buffer.byteLength(text);
|
|
221
|
+
if (budget.outputBytes > request.limits.maxOutputBytes)
|
|
222
|
+
throw new SafeError("BUDGET_EXCEEDED", "模型输出超过上限");
|
|
223
|
+
const { block, fresh } = blockFor(key, type);
|
|
224
|
+
if (fresh)
|
|
225
|
+
yield { type: "block-start", index: block.index, blockType: type };
|
|
226
|
+
block.text += text;
|
|
227
|
+
if (type === "text" && request.outputPolicy.visibility !== "internal")
|
|
228
|
+
this.store.event(this.runId, "output.delta", { text });
|
|
229
|
+
yield {
|
|
230
|
+
type: type === "text" ? "text-delta" : "reasoning-delta",
|
|
231
|
+
index: block.index,
|
|
232
|
+
text,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
if (Array.isArray(delta.tool_calls))
|
|
236
|
+
for (const raw of delta.tool_calls) {
|
|
237
|
+
const call = raw as Record<string, unknown>,
|
|
238
|
+
fn = call.function as Record<string, unknown> | undefined;
|
|
239
|
+
if (
|
|
240
|
+
!Number.isSafeInteger(call.index) ||
|
|
241
|
+
Number(call.index) < 0 ||
|
|
242
|
+
Number(call.index) > 63
|
|
243
|
+
)
|
|
244
|
+
throw new SafeError("TOOL_DENIED", "模型工具协议无效");
|
|
245
|
+
const { block, fresh } = blockFor(Number(call.index), "tool-call");
|
|
246
|
+
if (fresh)
|
|
247
|
+
yield {
|
|
248
|
+
type: "block-start",
|
|
249
|
+
index: block.index,
|
|
250
|
+
blockType: "tool-call",
|
|
251
|
+
};
|
|
252
|
+
if (typeof call.id === "string") block.id += call.id;
|
|
253
|
+
if (typeof fn?.name === "string") block.name += fn.name;
|
|
254
|
+
const argumentsDelta =
|
|
255
|
+
typeof fn?.arguments === "string" ? fn.arguments : "";
|
|
256
|
+
budget.outputBytes =
|
|
257
|
+
(budget.outputBytes ?? 0) + Buffer.byteLength(argumentsDelta);
|
|
258
|
+
if (budget.outputBytes > request.limits.maxOutputBytes)
|
|
259
|
+
throw new SafeError("BUDGET_EXCEEDED", "工具参数累计超过上限");
|
|
260
|
+
block.text += argumentsDelta;
|
|
261
|
+
if (Buffer.byteLength(block.text) > request.limits.maxOutputBytes)
|
|
262
|
+
throw new SafeError("BUDGET_EXCEEDED", "工具参数超过上限");
|
|
263
|
+
if (block.id)
|
|
264
|
+
yield {
|
|
265
|
+
type: "tool-call-delta",
|
|
266
|
+
index: block.index,
|
|
267
|
+
id: ToolCallId(block.id),
|
|
268
|
+
...(typeof fn?.name === "string" ? { name: fn.name } : {}),
|
|
269
|
+
argumentsDelta,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (!finish)
|
|
274
|
+
throw new SafeError("STREAM_INTERRUPTED", "模型响应意外中断", true);
|
|
275
|
+
for (const block of blocks.values()) {
|
|
276
|
+
let value: ContentBlock;
|
|
277
|
+
if (block.type === "tool-call") {
|
|
278
|
+
if (!block.id || !block.name)
|
|
279
|
+
throw new SafeError("TOOL_DENIED", "模型工具协议无效");
|
|
280
|
+
value = {
|
|
281
|
+
type: "tool-call",
|
|
282
|
+
id: ToolCallId(block.id),
|
|
283
|
+
name: block.name,
|
|
284
|
+
arguments: block.text,
|
|
285
|
+
};
|
|
286
|
+
} else value = { type: block.type, text: block.text };
|
|
287
|
+
yield { type: "block-end", index: block.index, block: value };
|
|
288
|
+
}
|
|
289
|
+
if (!usageSeen) {
|
|
290
|
+
budget.inputTokens += prepared.estimatedInputTokens;
|
|
291
|
+
budget.outputTokens += outputBytes;
|
|
292
|
+
}
|
|
293
|
+
if (
|
|
294
|
+
(request.limits.maxInputTokens &&
|
|
295
|
+
budget.inputTokens > request.limits.maxInputTokens) ||
|
|
296
|
+
(request.limits.maxOutputTokens &&
|
|
297
|
+
budget.outputTokens > request.limits.maxOutputTokens)
|
|
298
|
+
)
|
|
299
|
+
throw new SafeError("BUDGET_EXCEEDED", "模型 token 预算已耗尽");
|
|
300
|
+
if (finish === "length")
|
|
301
|
+
throw new SafeError("OUTPUT_TRUNCATED", "模型输出达到长度上限");
|
|
302
|
+
yield {
|
|
303
|
+
type: "finish",
|
|
304
|
+
reason:
|
|
305
|
+
finish === "tool_calls" ? { kind: "tool-calls" } : { kind: "stop" },
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LlmAdapter } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import type { RuntimeConfig } from "./config.js";
|
|
3
|
+
export abstract class FixedRouteAdapter extends LlmAdapter {
|
|
4
|
+
constructor(protected readonly config: RuntimeConfig) {
|
|
5
|
+
super();
|
|
6
|
+
}
|
|
7
|
+
override providerInfo(provider: string) {
|
|
8
|
+
return { id: provider, name: "Windy模型服务" };
|
|
9
|
+
}
|
|
10
|
+
override async listModels(provider: string) {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
provider,
|
|
14
|
+
id: this.config.model,
|
|
15
|
+
name: this.config.model,
|
|
16
|
+
inputModalities: this.config.inputModalities.includes("image")
|
|
17
|
+
? ["text" as const, "image" as const]
|
|
18
|
+
: ["text" as const],
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
override async resolveModel(provider: string, model: string) {
|
|
23
|
+
return {
|
|
24
|
+
provider,
|
|
25
|
+
id: model,
|
|
26
|
+
name: model,
|
|
27
|
+
inputModalities: this.config.inputModalities.includes("image")
|
|
28
|
+
? ["text" as const, "image" as const]
|
|
29
|
+
: ["text" as const],
|
|
30
|
+
context: { contextWindow: this.config.contextWindow },
|
|
31
|
+
defaultMaxTokens: this.config.maxOutputTokens,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { TokenUsage } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import { SafeError } from "./contracts.js";
|
|
3
|
+
export function parseUsage(usage: Record<string, unknown>) {
|
|
4
|
+
const inputTokens = Number(usage.prompt_tokens),
|
|
5
|
+
outputTokens = Number(usage.completion_tokens);
|
|
6
|
+
if (
|
|
7
|
+
![inputTokens, outputTokens].every(
|
|
8
|
+
(value) => Number.isSafeInteger(value) && value >= 0,
|
|
9
|
+
)
|
|
10
|
+
)
|
|
11
|
+
throw new SafeError("PROVIDER_UNAVAILABLE", "模型计量无效");
|
|
12
|
+
const details = usage.prompt_tokens_details as
|
|
13
|
+
| Record<string, unknown>
|
|
14
|
+
| undefined;
|
|
15
|
+
const completion = usage.completion_tokens_details as
|
|
16
|
+
| Record<string, unknown>
|
|
17
|
+
| undefined;
|
|
18
|
+
const rawCached = details?.cached_tokens ?? usage.prompt_cache_hit_tokens,
|
|
19
|
+
rawReasoning = completion?.reasoning_tokens;
|
|
20
|
+
const cached =
|
|
21
|
+
typeof rawCached === "number" &&
|
|
22
|
+
Number.isSafeInteger(rawCached) &&
|
|
23
|
+
rawCached >= 0 &&
|
|
24
|
+
rawCached <= inputTokens
|
|
25
|
+
? rawCached
|
|
26
|
+
: undefined;
|
|
27
|
+
const reasoning =
|
|
28
|
+
typeof rawReasoning === "number" &&
|
|
29
|
+
Number.isSafeInteger(rawReasoning) &&
|
|
30
|
+
rawReasoning >= 0 &&
|
|
31
|
+
rawReasoning <= outputTokens
|
|
32
|
+
? rawReasoning
|
|
33
|
+
: undefined;
|
|
34
|
+
const canonical = {
|
|
35
|
+
source: "provider-reported",
|
|
36
|
+
cacheStatus: cached === undefined ? "unknown" : cached > 0 ? "hit" : "miss",
|
|
37
|
+
inputTokens,
|
|
38
|
+
outputTokens,
|
|
39
|
+
totalTokens: inputTokens + outputTokens,
|
|
40
|
+
...(cached === undefined ? {} : { cachedInputTokens: cached }),
|
|
41
|
+
...(reasoning === undefined ? {} : { reasoningTokens: reasoning }),
|
|
42
|
+
};
|
|
43
|
+
const dsh: TokenUsage = {
|
|
44
|
+
inputTokens: inputTokens - (cached ?? 0),
|
|
45
|
+
outputTokens,
|
|
46
|
+
totalTokens: inputTokens + outputTokens,
|
|
47
|
+
...(cached === undefined ? {} : { cacheReadTokens: cached }),
|
|
48
|
+
...(reasoning === undefined ? {} : { reasoningTokens: reasoning }),
|
|
49
|
+
};
|
|
50
|
+
return { canonical, dsh };
|
|
51
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { RequestMessage } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import { SafeError } from "./contracts.js";
|
|
3
|
+
export function wireMessage(
|
|
4
|
+
message: RequestMessage,
|
|
5
|
+
images: ReadonlyMap<string, string> = new Map(),
|
|
6
|
+
): Record<string, unknown> {
|
|
7
|
+
const text = message.content
|
|
8
|
+
.filter((block) => block.type === "text")
|
|
9
|
+
.map((block) => block.text)
|
|
10
|
+
.join("\n");
|
|
11
|
+
if (message.content.some((block) => block.type === "file"))
|
|
12
|
+
throw new SafeError(
|
|
13
|
+
"INVALID_INPUT",
|
|
14
|
+
"此模型调用不支持直接附件,请使用文件工具",
|
|
15
|
+
);
|
|
16
|
+
const result: Record<string, unknown> = {
|
|
17
|
+
role: message.role === "developer" ? "system" : message.role,
|
|
18
|
+
content: text,
|
|
19
|
+
};
|
|
20
|
+
const imageBlocks = message.content.filter((block) => block.type === "image");
|
|
21
|
+
if (imageBlocks.length)
|
|
22
|
+
result.content = [
|
|
23
|
+
{ type: "text", text },
|
|
24
|
+
...imageBlocks.map((block) => {
|
|
25
|
+
const dataUrl = images.get(block.attachment.attachmentId);
|
|
26
|
+
if (!dataUrl)
|
|
27
|
+
throw new SafeError("INVALID_INPUT", "图片引用不属于当前任务");
|
|
28
|
+
return {
|
|
29
|
+
type: "image_url",
|
|
30
|
+
image_url: { url: dataUrl, detail: "auto" },
|
|
31
|
+
};
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
34
|
+
if (message.role === "tool") result.tool_call_id = message.toolCallId;
|
|
35
|
+
if (message.role === "assistant") {
|
|
36
|
+
const calls = message.content.filter((block) => block.type === "tool-call");
|
|
37
|
+
if (calls.length)
|
|
38
|
+
result.tool_calls = calls.map((block) => ({
|
|
39
|
+
id: block.id,
|
|
40
|
+
type: "function",
|
|
41
|
+
function: { name: block.name, arguments: block.arguments },
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { EventEmitter, once } from "node:events";
|
|
5
|
+
import type { ChildProcess } from "node:child_process";
|
|
6
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import WebSocket, { WebSocketServer } from "ws";
|
|
10
|
+
import { WorkbenchManager, type NativeWorker } from "../native/manager.js";
|
|
11
|
+
import { actorKey } from "../native/config.js";
|
|
12
|
+
import { attachWorkbenchSockets } from "../native/socket.js";
|
|
13
|
+
import { WorkbenchAuthorizationUnavailable } from "../native/authorization.js";
|
|
14
|
+
|
|
15
|
+
test(
|
|
16
|
+
"live sockets close on unavailable admission, recover on the same worker, and revoke definitively",
|
|
17
|
+
{ timeout: 10000 },
|
|
18
|
+
async () => {
|
|
19
|
+
const home = await mkdtemp(join(tmpdir(), "windy-socket-auth-"));
|
|
20
|
+
const upstream = createServer();
|
|
21
|
+
const upstreamWs = new WebSocketServer({ server: upstream });
|
|
22
|
+
upstreamWs.on("connection", (socket) =>
|
|
23
|
+
socket.on("message", (data) => socket.send(data)),
|
|
24
|
+
);
|
|
25
|
+
upstream.listen(0, "127.0.0.1");
|
|
26
|
+
await once(upstream, "listening");
|
|
27
|
+
const port = (upstream.address() as { port: number }).port;
|
|
28
|
+
let mode: "allowed" | "unavailable" | "denied" = "allowed";
|
|
29
|
+
const manager = new WorkbenchManager({
|
|
30
|
+
gateOrigin: "http://fixture",
|
|
31
|
+
authorize: async () => {
|
|
32
|
+
if (mode === "unavailable")
|
|
33
|
+
throw new WorkbenchAuthorizationUnavailable("upstream_status", 503);
|
|
34
|
+
return mode === "allowed";
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const authority = {
|
|
38
|
+
actorId: "socket-fixture",
|
|
39
|
+
session: "s".repeat(43),
|
|
40
|
+
publicOrigin: "http://localhost:18746",
|
|
41
|
+
};
|
|
42
|
+
const worker: NativeWorker = {
|
|
43
|
+
uid: 20000,
|
|
44
|
+
key: actorKey(authority.actorId),
|
|
45
|
+
authority,
|
|
46
|
+
token: "t".repeat(43),
|
|
47
|
+
cookie: "fixture=1",
|
|
48
|
+
port,
|
|
49
|
+
home,
|
|
50
|
+
child: Object.assign(new EventEmitter(), {
|
|
51
|
+
exitCode: 0,
|
|
52
|
+
signalCode: null,
|
|
53
|
+
}) as ChildProcess,
|
|
54
|
+
controller: new AbortController(),
|
|
55
|
+
admissionController: new AbortController(),
|
|
56
|
+
};
|
|
57
|
+
manager.workers.set(worker.key, worker);
|
|
58
|
+
const server = createServer();
|
|
59
|
+
const detach = attachWorkbenchSockets(server, manager, () => true);
|
|
60
|
+
server.listen(0, "127.0.0.1");
|
|
61
|
+
await once(server, "listening");
|
|
62
|
+
const proxyPort = (server.address() as { port: number }).port;
|
|
63
|
+
const clients: WebSocket[] = [];
|
|
64
|
+
const connect = () => {
|
|
65
|
+
const client = new WebSocket(
|
|
66
|
+
`ws://127.0.0.1:${proxyPort}/internal/workbench/api/remote.mux`,
|
|
67
|
+
{
|
|
68
|
+
headers: {
|
|
69
|
+
"x-windy-actor-id": authority.actorId,
|
|
70
|
+
"x-windy-product-session": authority.session,
|
|
71
|
+
"x-windy-public-origin": authority.publicOrigin,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
client.on("error", () => {});
|
|
76
|
+
clients.push(client);
|
|
77
|
+
return client;
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
const first = connect();
|
|
81
|
+
await once(first, "open");
|
|
82
|
+
const echoed = once(first, "message");
|
|
83
|
+
first.send("synthetic-ping");
|
|
84
|
+
assert.equal(String((await echoed)[0]), "synthetic-ping");
|
|
85
|
+
const firstClosed = once(first, "close");
|
|
86
|
+
mode = "unavailable";
|
|
87
|
+
await manager.inspect(worker);
|
|
88
|
+
await firstClosed;
|
|
89
|
+
assert.equal(worker.controller.signal.aborted, false);
|
|
90
|
+
assert.equal(manager.workers.get(worker.key), worker);
|
|
91
|
+
const rejected = connect();
|
|
92
|
+
const status = await new Promise<number>((resolve) =>
|
|
93
|
+
rejected.once("unexpected-response", (_, response) => {
|
|
94
|
+
response.resume();
|
|
95
|
+
resolve(response.statusCode!);
|
|
96
|
+
rejected.terminate();
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
assert.equal(status, 503);
|
|
100
|
+
mode = "allowed";
|
|
101
|
+
const recovered = connect();
|
|
102
|
+
await once(recovered, "open");
|
|
103
|
+
assert.equal(manager.workers.get(worker.key), worker);
|
|
104
|
+
const recoveredEcho = once(recovered, "message");
|
|
105
|
+
recovered.send("recovered");
|
|
106
|
+
assert.equal(String((await recoveredEcho)[0]), "recovered");
|
|
107
|
+
const revoked = once(recovered, "close");
|
|
108
|
+
mode = "denied";
|
|
109
|
+
await manager.inspect(worker);
|
|
110
|
+
await revoked;
|
|
111
|
+
assert.equal(worker.controller.signal.aborted, true);
|
|
112
|
+
assert.equal(manager.workers.size, 0);
|
|
113
|
+
} finally {
|
|
114
|
+
for (const client of clients) client.terminate();
|
|
115
|
+
detach();
|
|
116
|
+
for (const client of upstreamWs.clients) client.terminate();
|
|
117
|
+
upstreamWs.close();
|
|
118
|
+
await Promise.all([
|
|
119
|
+
new Promise<void>((resolve) => server.close(() => resolve())),
|
|
120
|
+
new Promise<void>((resolve) => upstream.close(() => resolve())),
|
|
121
|
+
]);
|
|
122
|
+
await manager.close();
|
|
123
|
+
await rm(home, { recursive: true, force: true });
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
);
|