create-windy 0.6.12 → 0.6.14
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 +572 -269
- package/package.json +1 -1
- package/template/.agents/skills/windy-business-module/SKILL.md +98 -70
- package/template/.windy-template.json +3 -3
- package/template/AGENTS.md +3 -6
- package/template/apps/agent-server/Dockerfile +2 -3
- package/template/apps/agent-server/README.md +38 -54
- package/template/apps/agent-server/pyproject.toml +0 -1
- package/template/apps/agent-server/src/southwind_agent_server/app.py +4 -2
- package/template/apps/agent-server/src/southwind_agent_server/attempt_context.py +191 -0
- package/template/apps/agent-server/src/southwind_agent_server/attempt_context_projection.py +203 -0
- package/template/apps/agent-server/src/southwind_agent_server/client_completion_contracts.py +61 -0
- package/template/apps/agent-server/src/southwind_agent_server/client_completion_governance.py +82 -0
- package/template/apps/agent-server/src/southwind_agent_server/client_completion_routes.py +121 -0
- package/template/apps/agent-server/src/southwind_agent_server/client_completion_runtime.py +158 -0
- package/template/apps/agent-server/src/southwind_agent_server/context_message_digest.py +24 -0
- package/template/apps/agent-server/src/southwind_agent_server/context_version_contracts.py +71 -0
- package/template/apps/agent-server/src/southwind_agent_server/context_version_port.py +307 -0
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +39 -0
- package/template/apps/agent-server/src/southwind_agent_server/deterministic.py +2 -0
- package/template/apps/agent-server/src/southwind_agent_server/engine.py +9 -1
- package/template/apps/agent-server/src/southwind_agent_server/engine_identity.py +2 -0
- package/template/apps/agent-server/src/southwind_agent_server/fingerprint.py +15 -0
- package/template/apps/agent-server/src/southwind_agent_server/health_routes.py +37 -3
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +46 -26
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine_validation.py +32 -0
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +7 -0
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_insert.py +5 -2
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_queries.py +1 -0
- package/template/apps/agent-server/src/southwind_agent_server/postgres_report_store.py +6 -1
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store.py +3 -2
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store_backend.py +1 -0
- package/template/apps/agent-server/src/southwind_agent_server/provider_governance.py +21 -0
- package/template/apps/agent-server/src/southwind_agent_server/report_lifecycle.py +2 -1
- package/template/apps/agent-server/src/southwind_agent_server/report_presenter.py +1 -0
- package/template/apps/agent-server/src/southwind_agent_server/report_routes.py +7 -1
- package/template/apps/agent-server/src/southwind_agent_server/report_store.py +10 -56
- package/template/apps/agent-server/src/southwind_agent_server/report_store_protocol.py +75 -0
- package/template/apps/agent-server/src/southwind_agent_server/report_types.py +9 -2
- package/template/apps/agent-server/src/southwind_agent_server/runtime_budget.py +74 -0
- package/template/apps/agent-server/src/southwind_agent_server/runtime_factory.py +11 -3
- package/template/apps/agent-server/src/southwind_agent_server/service.py +41 -65
- package/template/apps/agent-server/src/southwind_agent_server/service_control.py +64 -0
- package/template/apps/agent-server/src/southwind_agent_server/service_execution.py +3 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_errors.py +2 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_schema.py +9 -1
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_store.py +6 -5
- package/template/apps/agent-server/src/southwind_agent_server/store.py +2 -0
- package/template/apps/agent-server/src/southwind_agent_server/trajectory.py +137 -0
- package/template/apps/agent-server/src/southwind_agent_server/unavailable_engine.py +58 -0
- package/template/apps/agent-server/tests/test_api.py +30 -11
- package/template/apps/agent-server/tests/test_client_completion.py +230 -0
- package/template/apps/agent-server/tests/test_provider_attempt_reporting.py +12 -24
- package/template/apps/agent-server/tests/test_report_resilience.py +2 -0
- package/template/apps/agent-server/tests/test_report_routes.py +58 -1
- package/template/apps/agent-server/tests/test_report_summary_parity.py +1 -0
- package/template/apps/agent-server/tests/test_run_capacity.py +2 -0
- package/template/apps/agent-server/tests/test_runtime_factory_readiness.py +18 -3
- package/template/apps/agent-server/tests/test_trajectory.py +91 -0
- package/template/apps/agent-server/uv.lock +0 -259
- package/template/apps/server/Dockerfile +9 -4
- package/template/apps/server/src/agent/actor-projection-audit.ts +6 -0
- package/template/apps/server/src/agent/agent-run-delegation-policy.ts +115 -0
- package/template/apps/server/src/agent/agent-session-bootstrap.ts +23 -0
- package/template/apps/server/src/agent/{debug-session-facade-provider-failure.test.ts → agent-session-facade-provider-failure.test.ts} +24 -33
- package/template/apps/server/src/agent/{debug-session-facade.test.ts → agent-session-facade.test.ts} +34 -45
- package/template/apps/server/src/agent/{debug-session-facade.ts → agent-session-facade.ts} +50 -57
- package/template/apps/server/src/agent/{debug-session-id.test.ts → agent-session-id.test.ts} +5 -5
- package/template/apps/server/src/agent/{debug-session-id.ts → agent-session-id.ts} +7 -7
- package/template/apps/server/src/agent/{debug-session-provider-reader.ts → agent-session-provider-reader.ts} +18 -15
- package/template/apps/server/src/agent/{debug-session-routes.test.ts → agent-session-routes.test.ts} +16 -16
- package/template/apps/server/src/agent/{debug-session-routes.ts → agent-session-routes.ts} +12 -12
- package/template/apps/server/src/agent/{debug-session-validation.ts → agent-session-validation.ts} +13 -11
- package/template/apps/server/src/agent/client-session/authorization.ts +47 -0
- package/template/apps/server/src/agent/client-session/bootstrap.ts +96 -0
- package/template/apps/server/src/agent/client-session/capabilities.ts +19 -0
- package/template/apps/server/src/agent/client-session/completion.ts +299 -0
- package/template/apps/server/src/agent/client-session/contracts.ts +136 -0
- package/template/apps/server/src/agent/client-session/digest.ts +39 -0
- package/template/apps/server/src/agent/client-session/drizzle-repository.integration.test.ts +170 -0
- package/template/apps/server/src/agent/client-session/drizzle-repository.ts +345 -0
- package/template/apps/server/src/agent/client-session/errors.ts +28 -0
- package/template/apps/server/src/agent/client-session/fixtures/page-agent-1.12.2-request.json +52 -0
- package/template/apps/server/src/agent/client-session/host-auth.test.ts +144 -0
- package/template/apps/server/src/agent/client-session/host-auth.ts +110 -0
- package/template/apps/server/src/agent/client-session/manifest-admission.ts +240 -0
- package/template/apps/server/src/agent/client-session/openai-stream.ts +123 -0
- package/template/apps/server/src/agent/client-session/presentation.ts +46 -0
- package/template/apps/server/src/agent/client-session/remote-provider.test.ts +144 -0
- package/template/apps/server/src/agent/client-session/remote-provider.ts +216 -0
- package/template/apps/server/src/agent/client-session/repository.ts +225 -0
- package/template/apps/server/src/agent/client-session/request.test.ts +69 -0
- package/template/apps/server/src/agent/client-session/request.ts +289 -0
- package/template/apps/server/src/agent/client-session/revocation.ts +23 -0
- package/template/apps/server/src/agent/client-session/routes.ts +315 -0
- package/template/apps/server/src/agent/client-session/runtime-audit.ts +42 -0
- package/template/apps/server/src/agent/client-session/service.test-support.ts +226 -0
- package/template/apps/server/src/agent/client-session/service.test.ts +268 -0
- package/template/apps/server/src/agent/client-session/service.ts +346 -0
- package/template/apps/server/src/agent/context-memory/attempt-context-contracts.ts +60 -0
- package/template/apps/server/src/agent/context-memory/authoritative-source-registry.ts +127 -0
- package/template/apps/server/src/agent/context-memory/context-builder.test.ts +160 -0
- package/template/apps/server/src/agent/context-memory/context-builder.ts +184 -0
- package/template/apps/server/src/agent/context-memory/contracts.ts +284 -0
- package/template/apps/server/src/agent/context-memory/digest.ts +22 -0
- package/template/apps/server/src/agent/context-memory/memory-authorization.ts +82 -0
- package/template/apps/server/src/agent/context-memory/memory-content.ts +69 -0
- package/template/apps/server/src/agent/context-memory/memory-object-registry.ts +87 -0
- package/template/apps/server/src/agent/context-memory/memory-projector-contracts.ts +121 -0
- package/template/apps/server/src/agent/context-memory/memory-projector-validation.ts +155 -0
- package/template/apps/server/src/agent/context-memory/memory-projector.test.ts +19 -0
- package/template/apps/server/src/agent/context-memory/memory-projector.ts +259 -0
- package/template/apps/server/src/agent/context-memory/memory-retrieval-policy.ts +195 -0
- package/template/apps/server/src/agent/context-memory/memory-retriever.test.ts +339 -0
- package/template/apps/server/src/agent/context-memory/memory-retriever.ts +184 -0
- package/template/apps/server/src/agent/context-memory/search-provider-port.test.ts +62 -0
- package/template/apps/server/src/agent/context-memory/search-provider-port.ts +75 -0
- package/template/apps/server/src/agent/context-memory/working-context-expiry.ts +95 -0
- package/template/apps/server/src/agent/context-message-recovery.ts +23 -0
- package/template/apps/server/src/agent/context-version-routes.ts +241 -0
- package/template/apps/server/src/agent/context-version-runtime.ts +332 -0
- package/template/apps/server/src/agent/context-version-support.ts +93 -0
- package/template/apps/server/src/agent/context-version-validation.ts +118 -0
- package/template/apps/server/src/agent/drizzle-run-binding-repository.ts +11 -0
- package/template/apps/server/src/agent/idempotency-key.ts +9 -1
- package/template/apps/server/src/agent/memory-runtime-adapters.ts +266 -0
- package/template/apps/server/src/agent/memory-scope-binding.ts +14 -0
- package/template/apps/server/src/agent/module-ai-port-factory.ts +41 -0
- package/template/apps/server/src/agent/provider-input-governance.ts +19 -0
- package/template/apps/server/src/agent/remote-runtime-response.ts +162 -0
- package/template/apps/server/src/agent/remote-runtime.ts +53 -153
- package/template/apps/server/src/agent/run-audit.ts +2 -2
- package/template/apps/server/src/agent/run-authorization.test.ts +27 -0
- package/template/apps/server/src/agent/run-authorization.ts +60 -1
- package/template/apps/server/src/agent/run-binding-repository.ts +9 -0
- package/template/apps/server/src/agent/run-browser-authorization.ts +79 -0
- package/template/apps/server/src/agent/run-contracts.ts +23 -0
- package/template/apps/server/src/agent/run-facade.ts +139 -139
- package/template/apps/server/src/agent/run-failure-cleanup.ts +58 -0
- package/template/apps/server/src/agent/run-operation-policy.ts +20 -0
- package/template/apps/server/src/agent/run-route-input.ts +19 -1
- package/template/apps/server/src/agent/run-routes.ts +133 -5
- package/template/apps/server/src/agent/run-runtime-request.ts +89 -0
- package/template/apps/server/src/agent/run-session-authorization.ts +95 -0
- package/template/apps/server/src/agent/run-start-preparation.ts +71 -0
- package/template/apps/server/src/agent/runtime-bootstrap-input.ts +42 -0
- package/template/apps/server/src/agent/runtime-bootstrap-report.test.ts +53 -1
- package/template/apps/server/src/agent/runtime-bootstrap.ts +114 -111
- package/template/apps/server/src/agent/runtime-tool-composition.ts +38 -0
- package/template/apps/server/src/agent/session-context-source-support.ts +38 -0
- package/template/apps/server/src/agent/session-context-source.ts +346 -0
- package/template/apps/server/src/agent/session-invalidation/contracts.ts +217 -0
- package/template/apps/server/src/agent/session-invalidation/dispatcher.contract.test.ts +333 -0
- package/template/apps/server/src/agent/session-invalidation/dispatcher.ts +205 -0
- package/template/apps/server/src/agent/session-invalidation/module-authoritative-producer.test.ts +127 -0
- package/template/apps/server/src/agent/session-invalidation/module-authoritative-producer.ts +202 -0
- package/template/apps/server/src/agent/session-invalidation/read-guard.ts +39 -0
- package/template/apps/server/src/agent/session-invalidation/runtime.ts +69 -0
- package/template/apps/server/src/agent/session-invalidation/test-envelopes.ts +24 -0
- package/template/apps/server/src/agent/session-invalidation/worker.contract.test.ts +135 -0
- package/template/apps/server/src/agent/session-invalidation/worker.ts +76 -0
- package/template/apps/server/src/agent/session-log/checkpoint-digest.ts +36 -0
- package/template/apps/server/src/agent/session-log/domain.ts +123 -0
- package/template/apps/server/src/agent/session-log/events.ts +229 -0
- package/template/apps/server/src/agent/session-log/history.ts +143 -0
- package/template/apps/server/src/agent/session-log/in-memory-repository.ts +340 -0
- package/template/apps/server/src/agent/session-log/lifecycle.ts +67 -0
- package/template/apps/server/src/agent/session-log/replay-policy.ts +76 -0
- package/template/apps/server/src/agent/session-log/repository.ts +103 -0
- package/template/apps/server/src/agent/session-log/service.ts +349 -0
- package/template/apps/server/src/agent/session-log/session-log.test.ts +282 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-context-memory.ts +348 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-governed-context.ts +328 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-invalidation-outbox.ts +260 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-memory-projection-deletion.ts +56 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-run-projection-receipt.ts +80 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-session-fork.ts +147 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-session-list.ts +24 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-session-mapping.ts +154 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-session-mutations.ts +64 -0
- package/template/apps/server/src/agent/session-persistence/drizzle-session-repository.ts +335 -0
- package/template/apps/server/src/agent/session-persistence/invalidation-projections.ts +229 -0
- package/template/apps/server/src/agent/session-persistence/payload-codec.ts +90 -0
- package/template/apps/server/src/agent/session-projection-access.ts +155 -0
- package/template/apps/server/src/agent/session-projection-bootstrap.ts +87 -0
- package/template/apps/server/src/agent/session-projection-errors.ts +22 -0
- package/template/apps/server/src/agent/session-projection-facade.ts +349 -0
- package/template/apps/server/src/agent/session-projection-routes.ts +215 -0
- package/template/apps/server/src/agent/session-projection-view.ts +137 -0
- package/template/apps/server/src/agent/session-result-memory.ts +228 -0
- package/template/apps/server/src/agent/session-run-lifecycle.ts +85 -0
- package/template/apps/server/src/agent/session-run-link-contracts.ts +56 -0
- package/template/apps/server/src/agent/session-run-link.ts +343 -0
- package/template/apps/server/src/agent/session-run-recovery.ts +16 -0
- package/template/apps/server/src/agent/session-runtime-composition.ts +265 -0
- package/template/apps/server/src/agent/session-source-chain-authorizer.ts +141 -0
- package/template/apps/server/src/agent/session-terminal-reconciler.ts +100 -0
- package/template/apps/server/src/agent/session-turn-state.ts +49 -0
- package/template/apps/server/src/agent/tool-audit.ts +3 -3
- package/template/apps/server/src/agent/tool-execution-receipt.ts +13 -0
- package/template/apps/server/src/agent/tool-host.ts +41 -4
- package/template/apps/server/src/agent/tool-registry-composition.ts +52 -0
- package/template/apps/server/src/agent/tool-registry.test.ts +5 -5
- package/template/apps/server/src/agent/tool-registry.ts +53 -59
- package/template/apps/server/src/agent/unavailable-routes.ts +49 -5
- package/template/apps/server/src/agent/workflow-durable-runtime-input.ts +32 -0
- package/template/apps/server/src/agent/workflow-runtime-bootstrap.ts +59 -0
- package/template/apps/server/src/agent-workflow/adapter-dispatch.ts +148 -0
- package/template/apps/server/src/agent-workflow/approval-node-adapter.ts +77 -0
- package/template/apps/server/src/agent-workflow/artifact-access-error.ts +9 -0
- package/template/apps/server/src/agent-workflow/artifact-node-adapter.ts +67 -0
- package/template/apps/server/src/agent-workflow/artifact-policy.ts +71 -0
- package/template/apps/server/src/agent-workflow/artifact-source-authorization.ts +85 -0
- package/template/apps/server/src/agent-workflow/authorization.ts +238 -0
- package/template/apps/server/src/agent-workflow/budget-ledger.ts +118 -0
- package/template/apps/server/src/agent-workflow/budget-validation.ts +305 -0
- package/template/apps/server/src/agent-workflow/canonical-agent-run-binding.ts +17 -0
- package/template/apps/server/src/agent-workflow/canonical-agent-run-evidence.ts +142 -0
- package/template/apps/server/src/agent-workflow/canonical-agent-run-port.ts +304 -0
- package/template/apps/server/src/agent-workflow/canonical-agent-run-remote.ts +64 -0
- package/template/apps/server/src/agent-workflow/canonical-json.ts +16 -0
- package/template/apps/server/src/agent-workflow/command-drive.ts +195 -0
- package/template/apps/server/src/agent-workflow/command-error.ts +9 -0
- package/template/apps/server/src/agent-workflow/command-facade.ts +290 -0
- package/template/apps/server/src/agent-workflow/command-input.ts +133 -0
- package/template/apps/server/src/agent-workflow/condition-node-adapter.ts +69 -0
- package/template/apps/server/src/agent-workflow/definition-budget-validation.ts +41 -0
- package/template/apps/server/src/agent-workflow/definition-node-validation.ts +197 -0
- package/template/apps/server/src/agent-workflow/definition-validation.ts +198 -0
- package/template/apps/server/src/agent-workflow/delegated-tool-authorization.ts +15 -0
- package/template/apps/server/src/agent-workflow/delegation-child-delivery.ts +129 -0
- package/template/apps/server/src/agent-workflow/delegation-execution-authorization.ts +218 -0
- package/template/apps/server/src/agent-workflow/delegation-policy-validation.ts +253 -0
- package/template/apps/server/src/agent-workflow/delegation-policy.ts +179 -0
- package/template/apps/server/src/agent-workflow/drizzle-artifact-port.ts +211 -0
- package/template/apps/server/src/agent-workflow/drizzle-artifact-support.ts +152 -0
- package/template/apps/server/src/agent-workflow/drizzle-budget-ledger-settlement.ts +271 -0
- package/template/apps/server/src/agent-workflow/drizzle-budget-ledger-support.ts +226 -0
- package/template/apps/server/src/agent-workflow/drizzle-budget-ledger.ts +189 -0
- package/template/apps/server/src/agent-workflow/drizzle-cancellation-reconcile.ts +177 -0
- package/template/apps/server/src/agent-workflow/drizzle-delegated-tool-authorization.ts +155 -0
- package/template/apps/server/src/agent-workflow/drizzle-delegation-completion.ts +84 -0
- package/template/apps/server/src/agent-workflow/drizzle-delegation-lifecycle.ts +139 -0
- package/template/apps/server/src/agent-workflow/drizzle-delegation-port.ts +288 -0
- package/template/apps/server/src/agent-workflow/drizzle-effect-command-fence.ts +333 -0
- package/template/apps/server/src/agent-workflow/drizzle-evaluation-repository.ts +214 -0
- package/template/apps/server/src/agent-workflow/drizzle-event-validation.ts +43 -0
- package/template/apps/server/src/agent-workflow/drizzle-recovery-admission.ts +115 -0
- package/template/apps/server/src/agent-workflow/drizzle-repository-lineage.ts +103 -0
- package/template/apps/server/src/agent-workflow/drizzle-repository-mappers.ts +317 -0
- package/template/apps/server/src/agent-workflow/drizzle-repository-write.ts +311 -0
- package/template/apps/server/src/agent-workflow/drizzle-repository.ts +285 -0
- package/template/apps/server/src/agent-workflow/drizzle-side-effect-repository.ts +83 -0
- package/template/apps/server/src/agent-workflow/drizzle-write-support.ts +101 -0
- package/template/apps/server/src/agent-workflow/durable-continuation-authorization.ts +109 -0
- package/template/apps/server/src/agent-workflow/durable-continuation-driver.ts +97 -0
- package/template/apps/server/src/agent-workflow/durable-continuation-runtime.ts +173 -0
- package/template/apps/server/src/agent-workflow/durable-job-node-adapter.ts +106 -0
- package/template/apps/server/src/agent-workflow/effect-command-fence.ts +250 -0
- package/template/apps/server/src/agent-workflow/evaluation-evidence-coordinates.ts +225 -0
- package/template/apps/server/src/agent-workflow/evaluation-evidence-metrics.ts +280 -0
- package/template/apps/server/src/agent-workflow/evaluation-evidence-reader.ts +326 -0
- package/template/apps/server/src/agent-workflow/evaluation-metrics-validation.ts +85 -0
- package/template/apps/server/src/agent-workflow/evaluation-projection.ts +70 -0
- package/template/apps/server/src/agent-workflow/evaluation-repository.ts +134 -0
- package/template/apps/server/src/agent-workflow/evaluation-service.ts +292 -0
- package/template/apps/server/src/agent-workflow/evaluation-tool-registration.ts +95 -0
- package/template/apps/server/src/agent-workflow/evaluation-validation.ts +331 -0
- package/template/apps/server/src/agent-workflow/event-validation.ts +277 -0
- package/template/apps/server/src/agent-workflow/governed-tool-schema.ts +55 -0
- package/template/apps/server/src/agent-workflow/in-memory-evaluation-repository.ts +123 -0
- package/template/apps/server/src/agent-workflow/in-memory-mutation-validation.ts +154 -0
- package/template/apps/server/src/agent-workflow/in-memory-repository-support.ts +277 -0
- package/template/apps/server/src/agent-workflow/in-memory-repository.ts +339 -0
- package/template/apps/server/src/agent-workflow/in-memory-side-effect-store.ts +78 -0
- package/template/apps/server/src/agent-workflow/input-receipt.ts +55 -0
- package/template/apps/server/src/agent-workflow/model-node-adapter.ts +86 -0
- package/template/apps/server/src/agent-workflow/model-pricing-catalog.ts +215 -0
- package/template/apps/server/src/agent-workflow/node-adapter-factory.ts +83 -0
- package/template/apps/server/src/agent-workflow/node-adapters.ts +50 -0
- package/template/apps/server/src/agent-workflow/node-execution-ports.ts +185 -0
- package/template/apps/server/src/agent-workflow/node-input-receipt-port.ts +42 -0
- package/template/apps/server/src/agent-workflow/node-result-receipt.ts +50 -0
- package/template/apps/server/src/agent-workflow/platform-node-adapter-support.ts +185 -0
- package/template/apps/server/src/agent-workflow/platform-node-adapters.ts +256 -0
- package/template/apps/server/src/agent-workflow/platform-node-approval.ts +146 -0
- package/template/apps/server/src/agent-workflow/platform-node-direct-adapters.ts +65 -0
- package/template/apps/server/src/agent-workflow/production-delegation-scope.ts +58 -0
- package/template/apps/server/src/agent-workflow/production-node-policies.ts +62 -0
- package/template/apps/server/src/agent-workflow/query-service.ts +198 -0
- package/template/apps/server/src/agent-workflow/release.ts +96 -0
- package/template/apps/server/src/agent-workflow/repository.ts +157 -0
- package/template/apps/server/src/agent-workflow/routes.ts +307 -0
- package/template/apps/server/src/agent-workflow/runtime-composition.ts +308 -0
- package/template/apps/server/src/agent-workflow/scheduler-cancellation-reconcile.ts +253 -0
- package/template/apps/server/src/agent-workflow/scheduler-cancellation-support.ts +145 -0
- package/template/apps/server/src/agent-workflow/scheduler-cancellation.ts +2 -0
- package/template/apps/server/src/agent-workflow/scheduler-context.ts +85 -0
- package/template/apps/server/src/agent-workflow/scheduler-deadline.ts +65 -0
- package/template/apps/server/src/agent-workflow/scheduler-effect-result.ts +205 -0
- package/template/apps/server/src/agent-workflow/scheduler-execution-convergence.ts +174 -0
- package/template/apps/server/src/agent-workflow/scheduler-execution.ts +211 -0
- package/template/apps/server/src/agent-workflow/scheduler-failure.ts +102 -0
- package/template/apps/server/src/agent-workflow/scheduler-join-cancellation.ts +282 -0
- package/template/apps/server/src/agent-workflow/scheduler-mutation-queue.ts +13 -0
- package/template/apps/server/src/agent-workflow/scheduler-node-timeout.ts +139 -0
- package/template/apps/server/src/agent-workflow/scheduler-parallel-dispatch.ts +99 -0
- package/template/apps/server/src/agent-workflow/scheduler-recovery-activation.ts +63 -0
- package/template/apps/server/src/agent-workflow/scheduler-recovery-budget.ts +41 -0
- package/template/apps/server/src/agent-workflow/scheduler-recovery-effect.ts +331 -0
- package/template/apps/server/src/agent-workflow/scheduler-recovery-event-time.ts +26 -0
- package/template/apps/server/src/agent-workflow/scheduler-recovery-failed-policy.ts +129 -0
- package/template/apps/server/src/agent-workflow/scheduler-recovery-node.ts +208 -0
- package/template/apps/server/src/agent-workflow/scheduler-recovery-policy-convergence.ts +140 -0
- package/template/apps/server/src/agent-workflow/scheduler-reservation-convergence.ts +40 -0
- package/template/apps/server/src/agent-workflow/scheduler-side-effect-execution.ts +249 -0
- package/template/apps/server/src/agent-workflow/scheduler-support.ts +235 -0
- package/template/apps/server/src/agent-workflow/scheduler-workflow-cancellation.ts +296 -0
- package/template/apps/server/src/agent-workflow/scheduler.ts +289 -0
- package/template/apps/server/src/agent-workflow/service-completion.ts +102 -0
- package/template/apps/server/src/agent-workflow/service-mutation-identity.ts +94 -0
- package/template/apps/server/src/agent-workflow/service-node-admission.ts +36 -0
- package/template/apps/server/src/agent-workflow/service-node-run-update.ts +55 -0
- package/template/apps/server/src/agent-workflow/service-recovery-events.ts +38 -0
- package/template/apps/server/src/agent-workflow/service-recovery.ts +264 -0
- package/template/apps/server/src/agent-workflow/service-retry.ts +86 -0
- package/template/apps/server/src/agent-workflow/service-run-command.ts +131 -0
- package/template/apps/server/src/agent-workflow/service-state-error.ts +21 -0
- package/template/apps/server/src/agent-workflow/service-state-invariants.ts +44 -0
- package/template/apps/server/src/agent-workflow/service-support.ts +152 -0
- package/template/apps/server/src/agent-workflow/service.ts +307 -0
- package/template/apps/server/src/agent-workflow/side-effect-state.ts +226 -0
- package/template/apps/server/src/agent-workflow/state-machine.ts +321 -0
- package/template/apps/server/src/agent-workflow/subagent-node-adapter.ts +229 -0
- package/template/apps/server/src/agent-workflow/tool-node-adapter.ts +259 -0
- package/template/apps/server/src/agent-workflow/usage.ts +149 -0
- package/template/apps/server/src/agent-workflow/wait-signal-service.ts +147 -0
- package/template/apps/server/src/agent-workflow/workflow-artifact-token.ts +109 -0
- package/template/apps/server/src/agent-workflow/workflow-value-validation.ts +101 -0
- package/template/apps/server/src/agent-workflow/workspace-policy.ts +109 -0
- package/template/apps/server/src/ai-runtime-report/remote-parser.ts +41 -0
- package/template/apps/server/src/ai-runtime-report/service.test.ts +2 -0
- package/template/apps/server/src/app/agent-runtime-composition.ts +38 -0
- package/template/apps/server/src/app/client-agent-host-auth-binding.ts +10 -0
- package/template/apps/server/src/auth/actor-resolver.test.ts +33 -0
- package/template/apps/server/src/auth/actor-resolver.ts +6 -1
- package/template/apps/server/src/auth/composition.ts +36 -0
- package/template/apps/server/src/auth/routes.test-support.ts +2 -0
- package/template/apps/server/src/auth/routes.test.ts +18 -0
- package/template/apps/server/src/auth/runtime.ts +2 -0
- package/template/apps/server/src/auth/service-options.ts +16 -0
- package/template/apps/server/src/auth/service.ts +7 -12
- package/template/apps/server/src/index.ts +35 -37
- package/template/apps/server/src/license/pairing-service.test.ts +1 -1
- package/template/apps/server/src/module-host/agent-session-memory-port.ts +91 -0
- package/template/apps/server/src/module-host/{debug-session-provider-registration.test.ts → agent-session-provider-registration.test.ts} +42 -17
- package/template/apps/server/src/module-host/{debug-session-provider-registration.ts → agent-session-provider-registration.ts} +18 -18
- package/template/apps/server/src/module-host/agent-source-invalidation-port.ts +53 -0
- package/template/apps/server/src/module-host/http-runtime.ts +14 -0
- package/template/apps/server/src/module-host/initialize-contracts.ts +4 -5
- package/template/apps/server/src/module-host/initialize.ts +4 -4
- package/template/apps/server/src/module-host/request-context.test.ts +5 -5
- package/template/apps/server/src/module-host/request-context.ts +8 -0
- package/template/apps/server/src/module-host/route-install-context.ts +65 -0
- package/template/apps/server/src/module-host/route-installer.ts +11 -56
- package/template/apps/server/src/module-host/scoped-host.ts +17 -12
- package/template/apps/server/src/module-host/storage-authorization-binding.test.ts +3 -3
- package/template/apps/server/src/module-host.ts +3 -5
- package/template/apps/server/src/runtime.ts +3 -36
- package/template/apps/server/src/storage/routes-stream-cancellation.test.ts +19 -0
- package/template/apps/server/src/storage/routes.ts +3 -1
- package/template/apps/server/src/system/actor.ts +15 -2
- package/template/apps/server/src/system/authorization-invalidation-bridge.ts +30 -0
- package/template/apps/server/src/system/authorization-invalidation-composition.ts +36 -0
- package/template/apps/server/src/system/drizzle-system.ts +8 -1
- package/template/apps/server/src/system/identity-route-config.ts +9 -1
- package/template/apps/server/src/system/routes.ts +3 -0
- package/template/apps/server/src/system/seed.ts +3 -0
- package/template/apps/server/src/system/user-account-policy.ts +91 -0
- package/template/apps/web/package.json +1 -0
- package/template/apps/web/src/layout/AppSidebar.vue +2 -0
- package/template/apps/web/src/pages/system/AgentSessionPage.vue +73 -0
- package/template/apps/web/src/pages/system/AgentSessionPage.webtest.ts +66 -0
- package/template/apps/web/src/pages/system/AgentWorkflowPage.vue +69 -0
- package/template/apps/web/src/pages/system/components/agent-session/AgentSessionDetail.vue +114 -0
- package/template/apps/web/src/pages/system/components/agent-session/AgentSessionList.vue +84 -0
- package/template/apps/web/src/pages/system/components/agent-session/ContextVersionPanel.vue +119 -0
- package/template/apps/web/src/pages/system/components/agent-session/ContextVersionPanel.webtest.ts +46 -0
- package/template/apps/web/src/pages/system/components/agent-session/MemoryProjectionPanel.vue +163 -0
- package/template/apps/web/src/pages/system/components/agent-session/MemoryProjectionPanel.webtest.ts +62 -0
- package/template/apps/web/src/pages/system/components/agent-session/SessionTimeline.vue +71 -0
- package/template/apps/web/src/pages/system/components/agent-session/SessionTimeline.webtest.ts +34 -0
- package/template/apps/web/src/pages/system/components/agent-session/agent-session-presenter.ts +56 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/WorkflowNodeCard.vue +39 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/WorkflowNodeDetail.vue +172 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/WorkflowRunDetail.vue +151 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/WorkflowRunGraph.vue +96 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/WorkflowRunList.vue +100 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/WorkflowRunSummary.vue +148 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/agent-workflow-presenter.ts +74 -0
- package/template/apps/web/src/pages/system/components/agent-workflow/workflow-graph-layout.ts +108 -0
- package/template/apps/web/src/pages/system/components/ai-runtime/AiRuntimeRunDetailDialog.vue +9 -0
- package/template/apps/web/src/pages/system/components/ai-runtime/AiRuntimeRunDetailDialog.webtest.ts +22 -0
- package/template/apps/web/src/pages/system/components/ai-runtime/AiRuntimeRunTable.webtest.ts +2 -0
- package/template/apps/web/src/pages/system/components/ai-runtime/AiRuntimeTrajectory.vue +118 -0
- package/template/apps/web/src/pages/system/composables/useAgentSessions.ts +209 -0
- package/template/apps/web/src/pages/system/composables/useAgentSessions.webtest.ts +138 -0
- package/template/apps/web/src/pages/system/composables/useAgentWorkflowRuns.ts +173 -0
- package/template/apps/web/src/router/index.ts +4 -0
- package/template/apps/web/src/router/platform-admin-route-bindings.ts +6 -0
- package/template/apps/web/src/services/agent-session-api.ts +159 -0
- package/template/apps/web/src/services/agent-session-api.webtest.ts +65 -0
- package/template/apps/web/src/services/agent-workflow-api.ts +181 -0
- package/template/apps/web/src/services/ai-runtime-api.ts +4 -0
- package/template/docker-compose.yml +11 -8
- package/template/docs/adr/0003-agent-session-event-source.md +3 -0
- package/template/docs/architecture/agent-harness.md +464 -0
- package/template/docs/architecture/agent-workflow.md +99 -0
- package/template/docs/architecture/ai-runtime.md +55 -47
- package/template/docs/architecture/module-host.md +4 -3
- package/template/docs/operations/adk-retirement.md +98 -0
- package/template/docs/operations/agent-session-memory.md +162 -0
- package/template/docs/operations/agent-session-troubleshooting.md +196 -0
- package/template/docs/operations/agent-workflow-recovery.md +74 -0
- package/template/docs/operations/incremental-delivery.md +1 -1
- package/template/docs/platform/agent-production-store.md +82 -0
- package/template/docs/platform/agent-run-reattachment.md +52 -0
- package/template/docs/platform/agent-runtime-observability.md +4 -3
- package/template/docs/platform/agent-runtime.md +116 -281
- package/template/docs/platform/agent-tool-approval.md +61 -0
- package/template/docs/platform/background-ai-operations.md +50 -0
- package/template/docs/platform/client-agent-session.md +173 -0
- package/template/docs/platform/embedding-ai-runtime.md +94 -0
- package/template/docs/platform/platform-authentication.md +5 -8
- package/template/package.json +0 -1
- package/template/packages/ai-client/index.ts +1 -0
- package/template/packages/ai-client/package.json +2 -1
- package/template/packages/ai-client/src/agent/client/client.ts +15 -2
- package/template/packages/ai-client/src/agent/client/run-protocol.test.ts +39 -25
- package/template/packages/ai-client/src/agent/client/types.ts +4 -0
- package/template/packages/ai-client/src/agent/contracts/contracts.test.ts +49 -7
- package/template/packages/ai-client/src/agent/contracts/events.ts +61 -0
- package/template/packages/ai-client/src/agent/contracts/runs.ts +1 -0
- package/template/packages/ai-client/src/client-agent/contracts.ts +131 -0
- package/template/packages/ai-client/src/client-agent/http.test.ts +60 -0
- package/template/packages/ai-client/src/client-agent/http.ts +66 -0
- package/template/packages/ai-client/src/client-agent/index.ts +3 -0
- package/template/packages/ai-client/src/client-agent/validation.test.ts +57 -0
- package/template/packages/ai-client/src/client-agent/validation.ts +152 -0
- package/template/packages/config/index.test.ts +18 -0
- package/template/packages/config/package.json +1 -1
- package/template/packages/config/src/platform-validation.ts +8 -0
- package/template/packages/config/src/platform.ts +22 -9
- package/template/packages/database/drizzle/0055_square_yellowjacket.sql +47 -0
- package/template/packages/database/drizzle/0056_tricky_living_mummy.sql +2 -0
- package/template/packages/database/drizzle/0057_mature_doomsday.sql +4 -0
- package/template/packages/database/drizzle/0058_agent_session_memory.sql +159 -0
- package/template/packages/database/drizzle/0059_agent_source_module_key.sql +16 -0
- package/template/packages/database/drizzle/0060_slimy_rocket_raccoon.sql +43 -0
- package/template/packages/database/drizzle/0061_agent_workflow.sql +303 -0
- package/template/packages/database/drizzle/meta/0055_snapshot.json +11071 -0
- package/template/packages/database/drizzle/meta/0056_snapshot.json +11098 -0
- package/template/packages/database/drizzle/meta/0057_snapshot.json +10878 -0
- package/template/packages/database/drizzle/meta/0058_snapshot.json +12294 -0
- package/template/packages/database/drizzle/meta/0059_snapshot.json +12344 -0
- package/template/packages/database/drizzle/meta/0060_snapshot.json +12326 -0
- package/template/packages/database/drizzle/meta/0061_snapshot.json +14395 -0
- package/template/packages/database/drizzle/meta/_journal.json +49 -0
- package/template/packages/database/package.json +1 -1
- package/template/packages/database/src/agent-runtime-schema.test.ts +26 -0
- package/template/packages/database/src/schema/agent-context-message.ts +38 -0
- package/template/packages/database/src/schema/agent-runtime.ts +7 -0
- package/template/packages/database/src/schema/agent-session-receipt.ts +36 -0
- package/template/packages/database/src/schema/agent-session.ts +344 -0
- package/template/packages/database/src/schema/agent-workflow-delegation.ts +126 -0
- package/template/packages/database/src/schema/agent-workflow-effects.ts +213 -0
- package/template/packages/database/src/schema/agent-workflow-evaluation.ts +67 -0
- package/template/packages/database/src/schema/agent-workflow.ts +270 -0
- package/template/packages/database/src/schema/client-agent.ts +95 -0
- package/template/packages/database/src/schema/index.ts +8 -0
- package/template/packages/jobs/package.json +1 -1
- package/template/packages/modules/index.ts +2 -0
- package/template/packages/modules/package.json +1 -1
- package/template/packages/modules/src/ai-client-execution-composition.test.ts +98 -0
- package/template/packages/modules/src/ai-client-execution-policy.ts +54 -0
- package/template/packages/modules/src/ai-operation-composition.ts +2 -0
- package/template/packages/modules/src/manifest.ts +15 -0
- package/template/packages/modules/src/system-admin-routes.ts +16 -0
- package/template/packages/modules/src/system-admin-ui-catalog.ts +4 -1
- package/template/packages/modules/src/system-agent-audit-actions.ts +26 -0
- package/template/packages/modules/src/system-ai-api-bindings.ts +262 -0
- package/template/packages/modules/src/system-api-control-plane.ts +4 -78
- package/template/packages/modules/src/system-audit-actions.ts +113 -0
- package/template/packages/modules/src/system-features.ts +17 -0
- package/template/packages/modules/src/system-module-catalog.ts +21 -11
- package/template/packages/modules/src/system-modules.ts +22 -0
- package/template/packages/modules/src/system-permissions.ts +8 -0
- package/template/packages/server-sdk/index.ts +43 -0
- package/template/packages/server-sdk/package.json +5 -1
- package/template/packages/server-sdk/src/agent-session-memory-port.ts +64 -0
- package/template/packages/server-sdk/src/agent-session-provider.ts +63 -0
- package/template/packages/server-sdk/src/agent-source-invalidation-port.ts +54 -0
- package/template/packages/server-sdk/src/ai-operation-registration.ts +2 -0
- package/template/packages/server-sdk/src/client-agent-session.ts +95 -0
- package/template/packages/server-sdk/src/debug-session-provider.ts +14 -63
- package/template/packages/server-sdk/src/module-host.ts +7 -3
- package/template/packages/server-sdk/src/request-context.ts +6 -0
- package/template/packages/shared/index.ts +3 -0
- package/template/packages/shared/package.json +1 -1
- package/template/packages/shared/src/agent-workflow-definition.ts +113 -0
- package/template/packages/shared/src/agent-workflow-delegation.ts +123 -0
- package/template/packages/shared/src/agent-workflow-evaluation.ts +159 -0
- package/template/packages/shared/src/agent-workflow-events.ts +99 -0
- package/template/packages/shared/src/agent-workflow-run.ts +259 -0
- package/template/packages/shared/src/agent-workflow.ts +3 -0
- package/template/packages/shared/src/ai-runtime-report.ts +25 -0
- package/template/packages/shared/src/rbac.ts +24 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/upload-streams.test.ts +31 -0
- package/template/packages/storage/src/upload-streams.ts +20 -6
- package/template/apps/agent-server/adk_web_agents/__init__.py +0 -1
- package/template/apps/agent-server/adk_web_agents/canonical_debug/__init__.py +0 -1
- package/template/apps/agent-server/adk_web_agents/canonical_debug/agent.py +0 -145
- package/template/apps/agent-server/adk_web_agents/safe_debug/__init__.py +0 -3
- package/template/apps/agent-server/adk_web_agents/safe_debug/agent.py +0 -40
- package/template/apps/agent-server/adk_web_agents/services.py +0 -25
- package/template/apps/agent-server/project/adk-web-debug.json +0 -4
- package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +0 -333
- package/template/apps/agent-server/src/southwind_agent_server/adk_debug.py +0 -348
- package/template/apps/agent-server/src/southwind_agent_server/adk_debug_sessions.py +0 -325
- package/template/apps/agent-server/src/southwind_agent_server/adk_failure.py +0 -13
- package/template/apps/agent-server/src/southwind_agent_server/adk_model.py +0 -304
- package/template/apps/agent-server/src/southwind_agent_server/adk_tools.py +0 -143
- package/template/apps/agent-server/tests/test_adk_adapter.py +0 -307
- package/template/apps/agent-server/tests/test_adk_debug_result_polling.py +0 -139
- package/template/apps/agent-server/tests/test_adk_debug_sessions.py +0 -215
- package/template/apps/agent-server/tests/test_adk_web_agent.py +0 -12
- package/template/apps/agent-server/tests/test_adk_web_canonical_debug.py +0 -282
- package/template/apps/server/src/agent/run-debug-authorization.ts +0 -27
- package/template/apps/server/src/agent/run-facade-adk-debug.test.ts +0 -95
- package/template/apps/server/src/runtime-adk-debug.test.ts +0 -270
- package/template/apps/server/src/runtime-adk-debug.ts +0 -164
- package/template/apps/server/src/runtime-request-actor.test.ts +0 -55
- package/template/apps/server/src/runtime-request-actor.ts +0 -22
- package/template/docker-compose.agent-debug.yml +0 -58
- package/template/scripts/dev-adk-web.ts +0 -107
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import asyncio
|
|
4
|
-
from collections.abc import AsyncIterator
|
|
5
|
-
from typing import cast
|
|
6
|
-
|
|
7
|
-
from google.adk.agents import LlmAgent
|
|
8
|
-
from google.adk.agents.run_config import RunConfig, StreamingMode
|
|
9
|
-
from google.adk.events import Event
|
|
10
|
-
from google.adk.runners import Runner
|
|
11
|
-
from google.adk.sessions import InMemorySessionService
|
|
12
|
-
from google.genai import types
|
|
13
|
-
|
|
14
|
-
from .adk_failure import AdkFailureState
|
|
15
|
-
from .adk_model import GovernedOpenAiLlm
|
|
16
|
-
from .adk_tools import ApprovalSignalState, GovernedTool
|
|
17
|
-
from .engine import (
|
|
18
|
-
AgentEngineAdapter,
|
|
19
|
-
EngineCompleted,
|
|
20
|
-
EngineRunRequest,
|
|
21
|
-
EngineSignal,
|
|
22
|
-
OutputDelta,
|
|
23
|
-
SafeEngineError,
|
|
24
|
-
ToolCompleted,
|
|
25
|
-
ToolRequested,
|
|
26
|
-
UsageReported,
|
|
27
|
-
)
|
|
28
|
-
from .multimodal import final_output
|
|
29
|
-
from .openai_engine_validation import cancelled, validate_runtime_request
|
|
30
|
-
from .openai_provider import OpenAiCompatibleProvider
|
|
31
|
-
from .provider_governance import ProviderRequestGovernance
|
|
32
|
-
from .report_store import AgentRuntimeReportStore
|
|
33
|
-
from .report_types import CacheStatus, UsageFacts, UsageSource
|
|
34
|
-
from .tool_host import ToolHostClient, canonical_tool_call_id
|
|
35
|
-
from .vlm_readiness import VlmReadinessProbe, unavailable_vlm_snapshot
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class AdkEngineAdapter(AgentEngineAdapter):
|
|
39
|
-
"""Google ADK Runner implementation behind the stable engine seam."""
|
|
40
|
-
|
|
41
|
-
def __init__(
|
|
42
|
-
self,
|
|
43
|
-
provider: OpenAiCompatibleProvider | None = None,
|
|
44
|
-
tool_host: ToolHostClient | None = None,
|
|
45
|
-
governance: ProviderRequestGovernance | None = None,
|
|
46
|
-
report_store: AgentRuntimeReportStore | None = None,
|
|
47
|
-
) -> None:
|
|
48
|
-
self._provider = provider
|
|
49
|
-
self._tool_host = tool_host
|
|
50
|
-
self._governance = governance
|
|
51
|
-
self._report_store = report_store
|
|
52
|
-
self._cancellations: dict[str, asyncio.Event] = {}
|
|
53
|
-
|
|
54
|
-
@property
|
|
55
|
-
def capabilities(self) -> tuple[str, ...]:
|
|
56
|
-
return self._provider.config.capabilities if self._provider else ()
|
|
57
|
-
|
|
58
|
-
@property
|
|
59
|
-
def input_modalities(self) -> tuple[str, ...]:
|
|
60
|
-
return self._provider.config.input_modalities if self._provider else ()
|
|
61
|
-
|
|
62
|
-
@property
|
|
63
|
-
def max_concurrent_runs(self) -> int:
|
|
64
|
-
return self._provider.config.max_concurrent_runs if self._provider else 1
|
|
65
|
-
|
|
66
|
-
@property
|
|
67
|
-
def max_queue_depth(self) -> int:
|
|
68
|
-
return self._provider.config.max_queue_depth if self._provider else 0
|
|
69
|
-
|
|
70
|
-
def supports(self, operation_key: str) -> bool:
|
|
71
|
-
return bool(operation_key.strip())
|
|
72
|
-
|
|
73
|
-
async def execute(
|
|
74
|
-
self,
|
|
75
|
-
request: EngineRunRequest,
|
|
76
|
-
) -> AsyncIterator[EngineSignal]:
|
|
77
|
-
provider, tool_host, governance = self._configured()
|
|
78
|
-
validate_runtime_request(
|
|
79
|
-
request,
|
|
80
|
-
provider.config.deployment_key,
|
|
81
|
-
provider.config.capabilities,
|
|
82
|
-
provider.config.input_modalities,
|
|
83
|
-
)
|
|
84
|
-
cancellation = self._cancellations.setdefault(
|
|
85
|
-
request.run_id,
|
|
86
|
-
asyncio.Event(),
|
|
87
|
-
)
|
|
88
|
-
output = ""
|
|
89
|
-
output_bytes = 0
|
|
90
|
-
failures = AdkFailureState()
|
|
91
|
-
approvals = ApprovalSignalState()
|
|
92
|
-
event_failure: SafeEngineError | None = None
|
|
93
|
-
tool_call_ids: dict[str, str] = {}
|
|
94
|
-
try:
|
|
95
|
-
session_service = InMemorySessionService() # type: ignore[no-untyped-call]
|
|
96
|
-
await session_service.create_session(
|
|
97
|
-
app_name="southwind_runtime",
|
|
98
|
-
user_id="platform",
|
|
99
|
-
session_id=request.run_id,
|
|
100
|
-
)
|
|
101
|
-
runner = Runner(
|
|
102
|
-
app_name="southwind_runtime",
|
|
103
|
-
agent=LlmAgent(
|
|
104
|
-
name="southwind_operation",
|
|
105
|
-
model=GovernedOpenAiLlm(
|
|
106
|
-
request,
|
|
107
|
-
provider,
|
|
108
|
-
governance,
|
|
109
|
-
cancellation,
|
|
110
|
-
failures,
|
|
111
|
-
self._report_store,
|
|
112
|
-
),
|
|
113
|
-
instruction=request.instructions,
|
|
114
|
-
tools=[
|
|
115
|
-
GovernedTool(
|
|
116
|
-
tool,
|
|
117
|
-
request,
|
|
118
|
-
tool_host,
|
|
119
|
-
cancellation,
|
|
120
|
-
failures,
|
|
121
|
-
approvals,
|
|
122
|
-
)
|
|
123
|
-
for tool in request.allowed_tools
|
|
124
|
-
],
|
|
125
|
-
),
|
|
126
|
-
session_service=session_service,
|
|
127
|
-
)
|
|
128
|
-
events = runner.run_async(
|
|
129
|
-
user_id="platform",
|
|
130
|
-
session_id=request.run_id,
|
|
131
|
-
new_message=types.Content(
|
|
132
|
-
role="user",
|
|
133
|
-
parts=[types.Part(text=request.user_prompt)],
|
|
134
|
-
),
|
|
135
|
-
run_config=RunConfig(
|
|
136
|
-
streaming_mode=StreamingMode.SSE,
|
|
137
|
-
max_llm_calls=provider.config.max_tool_rounds,
|
|
138
|
-
),
|
|
139
|
-
)
|
|
140
|
-
async for item in merge_adk_events(events, approvals.queue):
|
|
141
|
-
if not isinstance(item, Event):
|
|
142
|
-
yield item
|
|
143
|
-
continue
|
|
144
|
-
event = item
|
|
145
|
-
cancelled(cancellation)
|
|
146
|
-
if event.error_code:
|
|
147
|
-
event_failure = failures.failure or SafeEngineError(
|
|
148
|
-
"PROVIDER_UNAVAILABLE",
|
|
149
|
-
"模型服务暂不可用",
|
|
150
|
-
retryable=True,
|
|
151
|
-
)
|
|
152
|
-
continue
|
|
153
|
-
async for signal in signals_for_event(
|
|
154
|
-
event,
|
|
155
|
-
request,
|
|
156
|
-
tool_call_ids,
|
|
157
|
-
):
|
|
158
|
-
if isinstance(signal, OutputDelta):
|
|
159
|
-
output_bytes += len(signal.text.encode())
|
|
160
|
-
if output_bytes > request.limits.max_output_bytes:
|
|
161
|
-
raise SafeEngineError(
|
|
162
|
-
"BUDGET_EXCEEDED",
|
|
163
|
-
"Agent 输出超过 Operation 上限",
|
|
164
|
-
retryable=False,
|
|
165
|
-
)
|
|
166
|
-
output += signal.text
|
|
167
|
-
yield signal
|
|
168
|
-
if event_failure is not None:
|
|
169
|
-
raise event_failure
|
|
170
|
-
cancelled(cancellation)
|
|
171
|
-
yield EngineCompleted(final_output(output, request.output_schema))
|
|
172
|
-
except SafeEngineError:
|
|
173
|
-
raise
|
|
174
|
-
except asyncio.CancelledError:
|
|
175
|
-
raise SafeEngineError(
|
|
176
|
-
"RUN_CANCELLED",
|
|
177
|
-
"Agent Run 已取消",
|
|
178
|
-
retryable=False,
|
|
179
|
-
) from None
|
|
180
|
-
except Exception:
|
|
181
|
-
raise SafeEngineError(
|
|
182
|
-
"RUNTIME_UNAVAILABLE",
|
|
183
|
-
"Agent Runtime 执行失败",
|
|
184
|
-
retryable=True,
|
|
185
|
-
) from None
|
|
186
|
-
finally:
|
|
187
|
-
self._cancellations.pop(request.run_id, None)
|
|
188
|
-
|
|
189
|
-
async def cancel(self, run_id: str) -> None:
|
|
190
|
-
cancellation = self._cancellations.get(run_id)
|
|
191
|
-
if cancellation is not None:
|
|
192
|
-
cancellation.set()
|
|
193
|
-
|
|
194
|
-
async def health(self) -> None:
|
|
195
|
-
self._configured()
|
|
196
|
-
|
|
197
|
-
async def readiness(self) -> dict[str, object]:
|
|
198
|
-
if not self._provider:
|
|
199
|
-
return unavailable_vlm_snapshot(configured=False)
|
|
200
|
-
return await VlmReadinessProbe(self._provider.config, self._provider).inspect()
|
|
201
|
-
|
|
202
|
-
def governance_health(self) -> dict[str, int | float | str | None]:
|
|
203
|
-
_, _, governance = self._configured()
|
|
204
|
-
return governance.health()
|
|
205
|
-
|
|
206
|
-
def _configured(
|
|
207
|
-
self,
|
|
208
|
-
) -> tuple[
|
|
209
|
-
OpenAiCompatibleProvider,
|
|
210
|
-
ToolHostClient,
|
|
211
|
-
ProviderRequestGovernance,
|
|
212
|
-
]:
|
|
213
|
-
if not self._provider or not self._tool_host or not self._governance:
|
|
214
|
-
raise SafeEngineError(
|
|
215
|
-
"RUNTIME_UNAVAILABLE",
|
|
216
|
-
"Agent Runtime 尚未配置",
|
|
217
|
-
retryable=True,
|
|
218
|
-
)
|
|
219
|
-
return self._provider, self._tool_host, self._governance
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
async def signals_for_event(
|
|
223
|
-
event: Event,
|
|
224
|
-
request: EngineRunRequest,
|
|
225
|
-
tool_call_ids: dict[str, str],
|
|
226
|
-
) -> AsyncIterator[EngineSignal]:
|
|
227
|
-
for call in event.get_function_calls():
|
|
228
|
-
if not call.id or not call.name:
|
|
229
|
-
raise SafeEngineError(
|
|
230
|
-
"TOOL_DENIED",
|
|
231
|
-
"模型请求了无效 Tool",
|
|
232
|
-
retryable=False,
|
|
233
|
-
)
|
|
234
|
-
arguments = call.args if isinstance(call.args, dict) else {}
|
|
235
|
-
stable_id = canonical_tool_call_id(
|
|
236
|
-
request.run_id,
|
|
237
|
-
call.name,
|
|
238
|
-
arguments,
|
|
239
|
-
)
|
|
240
|
-
tool_call_ids[call.id] = stable_id
|
|
241
|
-
yield ToolRequested(stable_id, call.name)
|
|
242
|
-
for response in event.get_function_responses():
|
|
243
|
-
if not response.id:
|
|
244
|
-
raise SafeEngineError(
|
|
245
|
-
"TOOL_DENIED",
|
|
246
|
-
"Agent Tool 响应缺少稳定标识",
|
|
247
|
-
retryable=False,
|
|
248
|
-
)
|
|
249
|
-
response_tool_call_id = tool_call_ids.get(response.id)
|
|
250
|
-
if not response_tool_call_id:
|
|
251
|
-
raise SafeEngineError(
|
|
252
|
-
"TOOL_DENIED",
|
|
253
|
-
"Agent Tool 响应与请求不匹配",
|
|
254
|
-
retryable=False,
|
|
255
|
-
)
|
|
256
|
-
yield ToolCompleted(response_tool_call_id)
|
|
257
|
-
if event.partial and event.content:
|
|
258
|
-
for part in event.content.parts or []:
|
|
259
|
-
if part.text and not part.thought:
|
|
260
|
-
yield OutputDelta(part.text)
|
|
261
|
-
usage = southwind_usage(event)
|
|
262
|
-
attempt_sequence = southwind_attempt_sequence(event)
|
|
263
|
-
if usage is not None and attempt_sequence is not None:
|
|
264
|
-
yield UsageReported(attempt_sequence, usage)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
def southwind_usage(event: Event) -> UsageFacts | None:
|
|
268
|
-
metadata = event.custom_metadata or {}
|
|
269
|
-
value = metadata.get("southwindUsage")
|
|
270
|
-
if not isinstance(value, dict):
|
|
271
|
-
return None
|
|
272
|
-
source = value.get("source")
|
|
273
|
-
cache_status = value.get("cacheStatus")
|
|
274
|
-
if source not in {"provider-reported", "estimated", "unknown"}:
|
|
275
|
-
return None
|
|
276
|
-
if cache_status not in {"hit", "miss", "unknown"}:
|
|
277
|
-
return None
|
|
278
|
-
return UsageFacts(
|
|
279
|
-
source=cast(UsageSource, source),
|
|
280
|
-
cache_status=cast(CacheStatus, cache_status),
|
|
281
|
-
input_tokens=measurement(value.get("inputTokens")),
|
|
282
|
-
output_tokens=measurement(value.get("outputTokens")),
|
|
283
|
-
cached_input_tokens=measurement(value.get("cachedInputTokens")),
|
|
284
|
-
reasoning_tokens=measurement(value.get("reasoningTokens")),
|
|
285
|
-
total_tokens=measurement(value.get("totalTokens")),
|
|
286
|
-
first_token_latency_ms=measurement(value.get("firstTokenLatencyMs")),
|
|
287
|
-
)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
def southwind_attempt_sequence(event: Event) -> int | None:
|
|
291
|
-
value = (event.custom_metadata or {}).get("southwindAttemptSequence")
|
|
292
|
-
return value if isinstance(value, int) and value > 0 else None
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
def measurement(value: object) -> int | None:
|
|
296
|
-
return (
|
|
297
|
-
value
|
|
298
|
-
if isinstance(value, int) and not isinstance(value, bool) and value >= 0
|
|
299
|
-
else None
|
|
300
|
-
)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
async def merge_adk_events(
|
|
304
|
-
events: AsyncIterator[Event],
|
|
305
|
-
approval_queue: asyncio.Queue[EngineSignal],
|
|
306
|
-
) -> AsyncIterator[Event | EngineSignal]:
|
|
307
|
-
iterator = events.__aiter__()
|
|
308
|
-
event_task: asyncio.Task[Event] = asyncio.create_task(next_event(iterator))
|
|
309
|
-
approval_task = asyncio.create_task(approval_queue.get())
|
|
310
|
-
try:
|
|
311
|
-
while True:
|
|
312
|
-
done, _ = await asyncio.wait(
|
|
313
|
-
{event_task, approval_task},
|
|
314
|
-
return_when=asyncio.FIRST_COMPLETED,
|
|
315
|
-
)
|
|
316
|
-
if approval_task in done:
|
|
317
|
-
yield approval_task.result()
|
|
318
|
-
approval_task = asyncio.create_task(approval_queue.get())
|
|
319
|
-
if event_task in done:
|
|
320
|
-
try:
|
|
321
|
-
yield event_task.result()
|
|
322
|
-
except StopAsyncIteration:
|
|
323
|
-
while not approval_queue.empty():
|
|
324
|
-
yield approval_queue.get_nowait()
|
|
325
|
-
return
|
|
326
|
-
event_task = asyncio.create_task(next_event(iterator))
|
|
327
|
-
finally:
|
|
328
|
-
event_task.cancel()
|
|
329
|
-
approval_task.cancel()
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
async def next_event(iterator: AsyncIterator[Event]) -> Event:
|
|
333
|
-
return await iterator.__anext__()
|
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import asyncio
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
import uuid
|
|
7
|
-
from collections.abc import AsyncIterator
|
|
8
|
-
from dataclasses import dataclass
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
from typing import Any, cast
|
|
11
|
-
|
|
12
|
-
import httpx
|
|
13
|
-
|
|
14
|
-
from .config import normalize_base_url
|
|
15
|
-
|
|
16
|
-
MAX_QUESTION_LENGTH = 4_000
|
|
17
|
-
MAX_VISIBLE_EVENTS = 64
|
|
18
|
-
MAX_EVENT_FRAME_BYTES = 64 * 1024
|
|
19
|
-
DEFAULT_RESULT_POLL_TIMEOUT_SECONDS = 60.0
|
|
20
|
-
DEFAULT_RESULT_POLL_INTERVAL_SECONDS = 0.5
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@dataclass(frozen=True)
|
|
24
|
-
class TextOperationDebugConfig:
|
|
25
|
-
operation_key: str
|
|
26
|
-
data_actor_id: str | None = None
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def load_text_operation_debug_config(
|
|
30
|
-
path: str | Path | None = None,
|
|
31
|
-
) -> TextOperationDebugConfig | None:
|
|
32
|
-
if path is None:
|
|
33
|
-
environment_key = os.environ.get("ADK_DEBUG_OPERATION_KEY", "").strip()
|
|
34
|
-
if environment_key:
|
|
35
|
-
return TextOperationDebugConfig(
|
|
36
|
-
operation_key=validate_operation_key(environment_key)
|
|
37
|
-
)
|
|
38
|
-
config_path = Path(path) if path else project_debug_config_path()
|
|
39
|
-
try:
|
|
40
|
-
value = json.loads(config_path.read_text(encoding="utf-8"))
|
|
41
|
-
except FileNotFoundError:
|
|
42
|
-
return None
|
|
43
|
-
except (OSError, UnicodeError, json.JSONDecodeError) as error:
|
|
44
|
-
raise RuntimeError("ADK Web 项目调试配置不可读") from error
|
|
45
|
-
if not isinstance(value, dict) or set(value) != {
|
|
46
|
-
"schemaVersion",
|
|
47
|
-
"textOperation",
|
|
48
|
-
}:
|
|
49
|
-
raise RuntimeError("ADK Web 项目调试配置格式无效")
|
|
50
|
-
schema_version = value.get("schemaVersion")
|
|
51
|
-
if (
|
|
52
|
-
not isinstance(schema_version, int)
|
|
53
|
-
or isinstance(schema_version, bool)
|
|
54
|
-
or schema_version != 1
|
|
55
|
-
):
|
|
56
|
-
raise RuntimeError("ADK Web 项目调试配置版本不受支持")
|
|
57
|
-
operation = value.get("textOperation")
|
|
58
|
-
if operation is None:
|
|
59
|
-
return None
|
|
60
|
-
if not isinstance(operation, dict) or set(operation) != {
|
|
61
|
-
"key",
|
|
62
|
-
"dataActorId",
|
|
63
|
-
}:
|
|
64
|
-
raise RuntimeError("ADK Web 文本 Operation 配置格式无效")
|
|
65
|
-
return TextOperationDebugConfig(
|
|
66
|
-
operation_key=validate_identifier(
|
|
67
|
-
operation.get("key"), "ADK Web 文本 Operation Key 无效"
|
|
68
|
-
),
|
|
69
|
-
data_actor_id=validate_identifier(
|
|
70
|
-
operation.get("dataActorId"), "ADK Web 真实开发数据用户无效"
|
|
71
|
-
),
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def validate_operation_key(value: object) -> str:
|
|
76
|
-
return validate_identifier(value, "ADK Web 文本 Operation Key 无效")
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def validate_identifier(value: object, message: str) -> str:
|
|
80
|
-
if (
|
|
81
|
-
not isinstance(value, str)
|
|
82
|
-
or not value.strip()
|
|
83
|
-
or len(value) > 200
|
|
84
|
-
or any(character.isspace() for character in value)
|
|
85
|
-
):
|
|
86
|
-
raise RuntimeError(message)
|
|
87
|
-
return value
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def project_debug_config_path() -> Path:
|
|
91
|
-
configured = os.environ.get("ADK_DEBUG_PROJECT_CONFIG", "").strip()
|
|
92
|
-
if configured:
|
|
93
|
-
return Path(configured)
|
|
94
|
-
return Path(__file__).resolve().parents[2] / "project" / "adk-web-debug.json"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
class CanonicalRunDebugClient:
|
|
98
|
-
def __init__(
|
|
99
|
-
self,
|
|
100
|
-
operation_key: str,
|
|
101
|
-
base_url: str,
|
|
102
|
-
bearer_token: str,
|
|
103
|
-
*,
|
|
104
|
-
transport: httpx.AsyncBaseTransport | None = None,
|
|
105
|
-
result_poll_timeout_seconds: float = DEFAULT_RESULT_POLL_TIMEOUT_SECONDS,
|
|
106
|
-
result_poll_interval_seconds: float = DEFAULT_RESULT_POLL_INTERVAL_SECONDS,
|
|
107
|
-
) -> None:
|
|
108
|
-
self._operation_key = operation_key
|
|
109
|
-
self._base_url = normalize_base_url(base_url)
|
|
110
|
-
self._bearer_token = bearer_token.strip()
|
|
111
|
-
self._transport = transport
|
|
112
|
-
if not 0 <= result_poll_timeout_seconds <= 120:
|
|
113
|
-
raise ValueError("result_poll_timeout_seconds 必须在 0 到 120 秒之间")
|
|
114
|
-
if not 0 < result_poll_interval_seconds <= 1:
|
|
115
|
-
raise ValueError("result_poll_interval_seconds 必须大于 0 且不超过 1 秒")
|
|
116
|
-
self._result_poll_timeout_seconds = result_poll_timeout_seconds
|
|
117
|
-
self._result_poll_interval_seconds = result_poll_interval_seconds
|
|
118
|
-
if not self._bearer_token:
|
|
119
|
-
raise RuntimeError("ADK_DEBUG_PLATFORM_TOKEN 未配置,拒绝启动真实调试 Run")
|
|
120
|
-
|
|
121
|
-
@classmethod
|
|
122
|
-
def from_environment(
|
|
123
|
-
cls,
|
|
124
|
-
operation_key: str,
|
|
125
|
-
) -> CanonicalRunDebugClient:
|
|
126
|
-
return cls(
|
|
127
|
-
operation_key,
|
|
128
|
-
os.environ.get("ADK_DEBUG_PLATFORM_URL", "http://server:9747"),
|
|
129
|
-
os.environ.get("ADK_DEBUG_PLATFORM_TOKEN", ""),
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
async def run(self, question: str) -> dict[str, object]:
|
|
133
|
-
prompt = question.strip()
|
|
134
|
-
if not prompt or len(prompt) > MAX_QUESTION_LENGTH:
|
|
135
|
-
raise RuntimeError("调试问题不能为空且最长 4000 字")
|
|
136
|
-
headers = {
|
|
137
|
-
"authorization": f"Bearer {self._bearer_token}",
|
|
138
|
-
"idempotency-key": f"adk-web-{uuid.uuid4()}",
|
|
139
|
-
"user-agent": "Windy-ADK-Web-Dev",
|
|
140
|
-
}
|
|
141
|
-
async with httpx.AsyncClient(
|
|
142
|
-
base_url=f"{self._base_url}/",
|
|
143
|
-
headers=headers,
|
|
144
|
-
timeout=httpx.Timeout(120),
|
|
145
|
-
transport=self._transport,
|
|
146
|
-
) as client:
|
|
147
|
-
started = await client.post(
|
|
148
|
-
"api/agent/runs",
|
|
149
|
-
json={
|
|
150
|
-
"operationKey": self._operation_key,
|
|
151
|
-
"input": {"question": prompt},
|
|
152
|
-
},
|
|
153
|
-
)
|
|
154
|
-
run_id = read_run_id(started)
|
|
155
|
-
events = await collect_compact_events(self._events(client, run_id))
|
|
156
|
-
try:
|
|
157
|
-
async with asyncio.timeout(self._result_poll_timeout_seconds):
|
|
158
|
-
while True:
|
|
159
|
-
result = await client.get(
|
|
160
|
-
f"api/agent/runs/{run_id}/result",
|
|
161
|
-
params={"operationKey": self._operation_key},
|
|
162
|
-
)
|
|
163
|
-
if result.is_success:
|
|
164
|
-
break
|
|
165
|
-
try:
|
|
166
|
-
error = result.json()
|
|
167
|
-
except json.JSONDecodeError:
|
|
168
|
-
error = None
|
|
169
|
-
if (
|
|
170
|
-
result.status_code != 409
|
|
171
|
-
or not isinstance(error, dict)
|
|
172
|
-
or error.get("code") != "RUN_CONFLICT"
|
|
173
|
-
or error.get("retryable") is not True
|
|
174
|
-
):
|
|
175
|
-
raise RuntimeError("平台 Agent Run 永久失败或结果读取失败")
|
|
176
|
-
await asyncio.sleep(self._result_poll_interval_seconds)
|
|
177
|
-
except TimeoutError as error:
|
|
178
|
-
raise RuntimeError("平台 Agent Run 结果等待超时") from error
|
|
179
|
-
answer = read_text_output(result, run_id)
|
|
180
|
-
if not any(event.get("type") == "run.completed" for event in events):
|
|
181
|
-
events = [*events[: MAX_VISIBLE_EVENTS - 1], {"type": "run.completed"}]
|
|
182
|
-
return {
|
|
183
|
-
"runId": run_id,
|
|
184
|
-
"answer": answer,
|
|
185
|
-
"events": events,
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async def _events(
|
|
189
|
-
self,
|
|
190
|
-
client: httpx.AsyncClient,
|
|
191
|
-
run_id: str,
|
|
192
|
-
) -> AsyncIterator[dict[str, object]]:
|
|
193
|
-
async with client.stream(
|
|
194
|
-
"GET",
|
|
195
|
-
f"api/agent/runs/{run_id}/events",
|
|
196
|
-
params={"operationKey": self._operation_key, "after": 0},
|
|
197
|
-
) as response:
|
|
198
|
-
if not response.is_success:
|
|
199
|
-
raise RuntimeError("平台 Agent Run 事件读取失败")
|
|
200
|
-
async for event in sse_events(response):
|
|
201
|
-
yield summarize_event(event)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
async def sse_events(response: httpx.Response) -> AsyncIterator[dict[str, object]]:
|
|
205
|
-
buffer = bytearray()
|
|
206
|
-
async for chunk in response.aiter_bytes(chunk_size=4096):
|
|
207
|
-
buffer.extend(chunk)
|
|
208
|
-
while separator := frame_separator(buffer):
|
|
209
|
-
index, width = separator
|
|
210
|
-
if index > MAX_EVENT_FRAME_BYTES:
|
|
211
|
-
raise RuntimeError("平台 Agent Run 单个事件超过调试上限")
|
|
212
|
-
frame = bytes(buffer[:index])
|
|
213
|
-
del buffer[: index + width]
|
|
214
|
-
event = parse_sse_frame(frame)
|
|
215
|
-
if event is not None:
|
|
216
|
-
yield event
|
|
217
|
-
if len(buffer) > MAX_EVENT_FRAME_BYTES:
|
|
218
|
-
raise RuntimeError("平台 Agent Run 单个事件超过调试上限")
|
|
219
|
-
if buffer:
|
|
220
|
-
event = parse_sse_frame(bytes(buffer))
|
|
221
|
-
if event is not None:
|
|
222
|
-
yield event
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
def frame_separator(buffer: bytearray) -> tuple[int, int] | None:
|
|
226
|
-
candidates = [
|
|
227
|
-
(index, len(separator))
|
|
228
|
-
for separator in (b"\n\n", b"\r\n\r\n")
|
|
229
|
-
if (index := buffer.find(separator)) >= 0
|
|
230
|
-
]
|
|
231
|
-
return min(candidates) if candidates else None
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
def parse_sse_frame(frame: bytes) -> dict[str, object] | None:
|
|
235
|
-
try:
|
|
236
|
-
lines = frame.decode("utf-8").splitlines()
|
|
237
|
-
except UnicodeDecodeError as error:
|
|
238
|
-
raise RuntimeError("平台 Agent Run 事件格式无效") from error
|
|
239
|
-
event_name = "message"
|
|
240
|
-
data: list[str] = []
|
|
241
|
-
for line in lines:
|
|
242
|
-
if not line or line.startswith(":"):
|
|
243
|
-
continue
|
|
244
|
-
if line.startswith("event:"):
|
|
245
|
-
event_name = line.removeprefix("event:").strip()
|
|
246
|
-
elif line.startswith("data:"):
|
|
247
|
-
value = line.removeprefix("data:")
|
|
248
|
-
data.append(value[1:] if value.startswith(" ") else value)
|
|
249
|
-
return parse_event(event_name, "\n".join(data)) if data else None
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
def parse_event(event_name: str, data: str) -> dict[str, object]:
|
|
253
|
-
try:
|
|
254
|
-
value = json.loads(data)
|
|
255
|
-
except json.JSONDecodeError as error:
|
|
256
|
-
raise RuntimeError("平台 Agent Run 事件格式无效") from error
|
|
257
|
-
if not isinstance(value, dict) or value.get("type") != event_name:
|
|
258
|
-
raise RuntimeError("平台 Agent Run 事件格式无效")
|
|
259
|
-
return cast(dict[str, object], value)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
def summarize_event(event: dict[str, object]) -> dict[str, object]:
|
|
263
|
-
fields = ("sequence", "type", "toolKey", "toolCallId", "workItemId", "outcome")
|
|
264
|
-
return {field: event[field] for field in fields if field in event}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
def compact_events(events: list[dict[str, object]]) -> list[dict[str, object]]:
|
|
268
|
-
compactor = EventCompactor()
|
|
269
|
-
for event in events:
|
|
270
|
-
compactor.add(event)
|
|
271
|
-
return compactor.finish()
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
async def collect_compact_events(
|
|
275
|
-
events: AsyncIterator[dict[str, object]],
|
|
276
|
-
) -> list[dict[str, object]]:
|
|
277
|
-
compactor = EventCompactor()
|
|
278
|
-
async for event in events:
|
|
279
|
-
compactor.add(event)
|
|
280
|
-
return compactor.finish()
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
@dataclass
|
|
284
|
-
class EventCompactor:
|
|
285
|
-
visible: list[dict[str, object]] | None = None
|
|
286
|
-
output_deltas: int = 0
|
|
287
|
-
hidden_events: int = 0
|
|
288
|
-
|
|
289
|
-
def add(self, event: dict[str, object]) -> None:
|
|
290
|
-
if event.get("type") == "output.delta":
|
|
291
|
-
self.output_deltas += 1
|
|
292
|
-
return
|
|
293
|
-
if self.visible is None:
|
|
294
|
-
self.visible = []
|
|
295
|
-
if len(self.visible) < MAX_VISIBLE_EVENTS:
|
|
296
|
-
self.visible.append(event)
|
|
297
|
-
else:
|
|
298
|
-
self.hidden_events += 1
|
|
299
|
-
|
|
300
|
-
def finish(self) -> list[dict[str, object]]:
|
|
301
|
-
visible = list(self.visible or [])
|
|
302
|
-
while True:
|
|
303
|
-
trailers = self._trailers()
|
|
304
|
-
if len(visible) + len(trailers) <= MAX_VISIBLE_EVENTS:
|
|
305
|
-
return [*visible, *trailers]
|
|
306
|
-
visible.pop()
|
|
307
|
-
self.hidden_events += 1
|
|
308
|
-
|
|
309
|
-
def _trailers(self) -> list[dict[str, object]]:
|
|
310
|
-
trailers: list[dict[str, object]] = []
|
|
311
|
-
if self.output_deltas:
|
|
312
|
-
trailers.append({"type": "output.delta", "count": self.output_deltas})
|
|
313
|
-
if self.hidden_events:
|
|
314
|
-
trailers.append({"type": "events.truncated", "count": self.hidden_events})
|
|
315
|
-
return trailers
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
def read_run_id(response: httpx.Response) -> str:
|
|
319
|
-
value = response_json(response, "平台 Agent Run 启动失败")
|
|
320
|
-
run_id = value.get("runId")
|
|
321
|
-
if not isinstance(run_id, str) or not run_id:
|
|
322
|
-
raise RuntimeError("平台 Agent Run 启动响应无效")
|
|
323
|
-
return run_id
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
def read_text_output(response: httpx.Response, expected_run_id: str) -> str:
|
|
327
|
-
value = response_json(response, "平台 Agent Run 未完成")
|
|
328
|
-
if value.get("runId") != expected_run_id or value.get("status") != "completed":
|
|
329
|
-
raise RuntimeError("平台 Agent Run 结果身份或状态无效")
|
|
330
|
-
output = value.get("output")
|
|
331
|
-
if not isinstance(output, dict):
|
|
332
|
-
raise RuntimeError("平台 Agent Run 输出不符合文本调试契约")
|
|
333
|
-
text = output.get("text")
|
|
334
|
-
if not isinstance(text, str):
|
|
335
|
-
raise RuntimeError("平台 Agent Run 输出不符合文本调试契约")
|
|
336
|
-
return text
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
def response_json(response: httpx.Response, message: str) -> dict[str, Any]:
|
|
340
|
-
if not response.is_success:
|
|
341
|
-
raise RuntimeError(message)
|
|
342
|
-
try:
|
|
343
|
-
value = response.json()
|
|
344
|
-
except json.JSONDecodeError as error:
|
|
345
|
-
raise RuntimeError(message) from error
|
|
346
|
-
if not isinstance(value, dict):
|
|
347
|
-
raise RuntimeError(message)
|
|
348
|
-
return cast(dict[str, Any], value)
|