agentengine-sdk-python 0.8.6__py3-none-any.whl → 0.8.7__py3-none-any.whl
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.
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.7.dist-info}/METADATA +31 -13
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.7.dist-info}/RECORD +655 -501
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.7.dist-info}/WHEEL +1 -1
- ksadk/_build_provenance.json +1 -1
- ksadk/a2a/_invocation_state.py +1 -1
- ksadk/a2a/adk_invocation_context.py +2 -1
- ksadk/a2a/adk_tools.py +19 -9
- ksadk/a2a/bootstrap.py +7 -6
- ksadk/a2a/codex.py +2 -1
- ksadk/a2a/control_plane.py +119 -2
- ksadk/a2a/executor.py +24 -7
- ksadk/a2a/invocation_service.py +198 -7
- ksadk/a2a/kernel_task_adapter.py +60 -9
- ksadk/a2a/langgraph_invocation_context.py +3 -2
- ksadk/a2a/langgraph_managed.py +17 -1
- ksadk/a2a/langgraph_recovery.py +43 -5
- ksadk/a2a/langgraph_tool_runtime.py +8 -6
- ksadk/a2a/langgraph_tools.py +13 -1
- ksadk/a2a/platform.py +8 -2
- ksadk/a2a/runtime_approval.py +6 -21
- ksadk/a2a/runtime_input.py +3 -2
- ksadk/a2a/timeouts.py +37 -0
- ksadk/a2a/tool_outcomes.py +73 -0
- ksadk/a2a/workload_tokens.py +21 -134
- ksadk/a2ui/__init__.py +4 -0
- ksadk/a2ui/assets/basic-v0_9_1.json +1383 -0
- ksadk/a2ui/assets/common-types-v0_9.json +305 -0
- ksadk/a2ui/assets/legacy-seven-components.json +230 -0
- ksadk/a2ui/assets/manifest.json +86 -0
- ksadk/a2ui/budget.py +54 -0
- ksadk/a2ui/catalog.py +64 -0
- ksadk/a2ui/generation.py +71 -0
- ksadk/a2ui/legacy.py +88 -0
- ksadk/a2ui/linking.py +115 -0
- ksadk/a2ui/payload.py +46 -0
- ksadk/a2ui/presentation.py +79 -0
- ksadk/a2ui/registry.py +166 -0
- ksadk/a2ui/wire.py +110 -0
- ksadk/agui/_agent_helpers.py +16 -1
- ksadk/agui/_agent_kernel.py +481 -0
- ksadk/agui/_agent_projection.py +379 -0
- ksadk/agui/_agent_resume.py +279 -0
- ksadk/agui/_agent_types.py +67 -0
- ksadk/agui/a2ui_projection.py +3 -1
- ksadk/agui/agent.py +110 -566
- ksadk/agui/config.py +19 -5
- ksadk/agui/routes.py +2 -0
- ksadk/api/client.py +158 -7
- ksadk/builders/code_builder.py +144 -29
- ksadk/builders/container_builder.py +27 -6
- ksadk/builders/framework_requirements.py +5 -4
- ksadk/builders/mcp_builder.py +3 -1
- ksadk/cli/cmd_deploy.py +5 -0
- ksadk/cli/cmd_invoke.py +57 -2
- ksadk/cli/cmd_studio.py +19 -3
- ksadk/cli/cmd_web.py +20 -56
- ksadk/cli/hosted_command_events.py +148 -0
- ksadk/cli/hosted_invoke.py +66 -14
- ksadk/cli/runtime_bootstrap.py +1 -0
- ksadk/codex/async_client.py +354 -12
- ksadk/codex/runtime.py +17 -2
- ksadk/common/diagnostics.py +15 -0
- ksadk/compat/copilotkit_a2ui.py +85 -21
- ksadk/configs/env_registry.py +71 -19
- ksadk/configs/env_registry_a2a.py +42 -0
- ksadk/conversations/a2ui_projection.py +50 -0
- ksadk/conversations/context.py +12 -0
- ksadk/conversations/message_projection.py +106 -60
- ksadk/conversations/message_projection_blocks.py +75 -3
- ksadk/conversations/message_projection_outcomes.py +81 -0
- ksadk/conversations/projector.py +29 -0
- ksadk/conversations/runtime_invocation.py +3 -0
- ksadk/conversations/runtime_projection.py +23 -1
- ksadk/conversations/runtime_stream_events.py +11 -7
- ksadk/conversations/runtime_streaming.py +21 -17
- ksadk/deployment/mcp.py +93 -0
- ksadk/deployment/providers/serverless.py +130 -4
- ksadk/events/_v1_compat/projection.py +2 -0
- ksadk/events/adapters/_langgraph_custom.py +195 -0
- ksadk/events/adapters/_langgraph_model_tasks.py +59 -0
- ksadk/events/adapters/_langgraph_support.py +80 -29
- ksadk/events/adapters/_langgraph_tool_outcomes.py +71 -0
- ksadk/events/adapters/_langgraph_usage_origin.py +86 -0
- ksadk/events/adapters/adk.py +11 -0
- ksadk/events/adapters/langgraph.py +188 -20
- ksadk/events/canonical.py +23 -1
- ksadk/events/canonical_store.py +133 -4
- ksadk/events/cold_recovery.py +2 -1
- ksadk/events/native_checkpoint.py +10 -0
- ksadk/events/reducer.py +9 -9
- ksadk/events/run_authority.py +15 -0
- ksadk/events/session_event.py +61 -0
- ksadk/events/sse_heartbeat.py +50 -0
- ksadk/events/usage.py +50 -0
- ksadk/harness/app.py +1 -1
- ksadk/harness/artifact_adapters/native_catalog.py +92 -0
- ksadk/harness/artifact_adapters/native_tool.py +16 -0
- ksadk/harness/browser_adapters/native_playwright.py +3 -1
- ksadk/harness/browser_adapters/native_vision.py +2 -1
- ksadk/harness/engine/postgres_checkpointer.py +170 -29
- ksadk/harness/model_adapters/native_openai.py +3 -1
- ksadk/harness/native/artifact_catalog_contract.py +26 -0
- ksadk/harness/native/artifact_partial_read_capacity.py +6 -3
- ksadk/harness/native/artifact_read_capacity.py +15 -87
- ksadk/harness/native/artifact_runtime.py +44 -1
- ksadk/harness/native/artifact_search_capacity.py +20 -119
- ksadk/harness/native/artifact_single_read_capacity.py +7 -6
- ksadk/harness/native/background_command_contract.py +40 -0
- ksadk/harness/native/background_commands.py +101 -0
- ksadk/harness/native/call_budget.py +24 -0
- ksadk/harness/native/child_budget.py +6 -6
- ksadk/harness/native/child_interruption.py +3 -2
- ksadk/harness/native/child_media.py +105 -0
- ksadk/harness/native/context.py +44 -0
- ksadk/harness/native/context_compaction_projection.py +38 -2
- ksadk/harness/native/context_continuation.py +54 -0
- ksadk/harness/native/context_contributions.py +2 -1
- ksadk/harness/native/context_directory_progress.py +117 -0
- ksadk/harness/native/context_driver.py +136 -11
- ksadk/harness/native/context_partial_summary.py +2 -0
- ksadk/harness/native/context_partition.py +37 -1
- ksadk/harness/native/context_replay.py +2 -1
- ksadk/harness/native/context_request_projection.py +59 -6
- ksadk/harness/native/context_runtime.py +211 -16
- ksadk/harness/native/context_runtime_contracts.py +123 -1
- ksadk/harness/native/context_session_history.py +96 -0
- ksadk/harness/native/context_source_progress.py +164 -5
- ksadk/harness/native/context_summary_planning.py +63 -15
- ksadk/harness/native/context_summary_prompt.py +72 -0
- ksadk/harness/native/context_summary_recovery.py +3 -1
- ksadk/harness/native/delivery_artifacts.py +58 -0
- ksadk/harness/native/delivery_context.py +64 -0
- ksadk/harness/native/delivery_feedback.py +95 -0
- ksadk/harness/native/delivery_review.py +10 -10
- ksadk/harness/native/effect_control.py +45 -1
- ksadk/harness/native/effect_receipts.py +50 -3
- ksadk/harness/native/effect_runtime.py +10 -1
- ksadk/harness/native/engine.py +601 -16
- ksadk/harness/native/execution_budget.py +88 -0
- ksadk/harness/native/history.py +1 -0
- ksadk/harness/native/machine.py +44 -7
- ksadk/harness/native/model.py +17 -3
- ksadk/harness/native/model_runtime.py +192 -12
- ksadk/harness/native/model_takeover.py +4 -2
- ksadk/harness/native/notification_admission.py +183 -0
- ksadk/harness/native/ports.py +54 -6
- ksadk/harness/native/run_clock.py +13 -6
- ksadk/harness/native/state.py +100 -1
- ksadk/harness/native/stream_display_buffer.py +198 -0
- ksadk/harness/native/subagents.py +21 -0
- ksadk/harness/native/task_policy.py +8 -3
- ksadk/harness/native/tool_batch_capacity.py +152 -0
- ksadk/harness/native/tool_budget.py +38 -9
- ksadk/harness/native/tool_error_recovery.py +241 -0
- ksadk/harness/native/tool_error_streak.py +10 -1
- ksadk/harness/native/tool_progress.py +1 -0
- ksadk/harness/native/tool_scheduling.py +9 -10
- ksadk/harness/native/turn_control.py +21 -2
- ksadk/harness/native/verification_runtime.py +2 -1
- ksadk/harness/native_facade.py +180 -9
- ksadk/harness/native_projection.py +18 -8
- ksadk/harness/native_runtime.py +208 -3
- ksadk/harness/provider_thinking.py +63 -0
- ksadk/harness/public_activity.py +3 -0
- ksadk/harness/skill_adapters/native_disclosure.py +13 -1
- ksadk/harness/skill_adapters/native_metadata.py +40 -0
- ksadk/harness/spec.py +6 -0
- ksadk/harness/stores/native_commit_history.py +373 -0
- ksadk/harness/stores/native_contract.py +205 -1
- ksadk/harness/stores/native_memory.py +363 -1
- ksadk/harness/stores/native_sqlite.py +572 -14
- ksadk/harness/stores/native_sqlite_migration.py +34 -7
- ksadk/harness/subagent.py +6 -1
- ksadk/harness/subagent_adapters/native_background_child.py +8 -7
- ksadk/harness/subagent_adapters/native_child.py +87 -8
- ksadk/harness/tool_display.py +113 -2
- ksadk/harness/tool_display_contract.py +34 -1
- ksadk/interaction/contracts.py +19 -4
- ksadk/interaction/display_values.py +140 -0
- ksadk/interaction/form_values.py +130 -0
- ksadk/interaction/langgraph.py +53 -0
- ksadk/interaction/langgraph_approval.py +59 -0
- ksadk/interaction/langgraph_interrupt.py +129 -0
- ksadk/interaction/langgraph_observer.py +125 -0
- ksadk/interaction/ledger.py +32 -5
- ksadk/interaction/native_events.py +29 -0
- ksadk/interaction/providers/langgraph.py +19 -8
- ksadk/interaction/resolution.py +43 -0
- ksadk/interaction/schema.py +168 -0
- ksadk/interaction/submission.py +184 -0
- ksadk/kernel/admission_cursor.py +19 -0
- ksadk/kernel/bootstrap.py +344 -228
- ksadk/kernel/contract_fingerprints.py +5 -0
- ksadk/kernel/contracts.py +1 -0
- ksadk/kernel/control.py +67 -0
- ksadk/kernel/conversation_input.py +39 -0
- ksadk/kernel/execution_host_ingress.py +6 -3
- ksadk/kernel/history_projection.py +85 -4
- ksadk/kernel/ingress.py +63 -11
- ksadk/kernel/interactions_memory.py +447 -0
- ksadk/kernel/interactions_postgres.py +500 -0
- ksadk/kernel/interactions_sqlite.py +684 -0
- ksadk/kernel/legacy_postgres_repair.py +113 -0
- ksadk/kernel/local_interactions.py +172 -0
- ksadk/kernel/memory_store.py +137 -366
- ksadk/kernel/native_confirmation.py +109 -0
- ksadk/kernel/postgres_locks.py +23 -0
- ksadk/kernel/postgres_store.py +573 -511
- ksadk/kernel/postgres_time.py +12 -0
- ksadk/kernel/recovery.py +26 -1
- ksadk/kernel/runtime_config.py +72 -0
- ksadk/kernel/runtime_environment.py +301 -0
- ksadk/kernel/session_storage.py +144 -0
- ksadk/kernel/sql/002_session_retirement.sql +86 -0
- ksadk/kernel/sql/003_legacy_repair_queue.sql +49 -0
- ksadk/kernel/sql/backfill_session_namespaces.sql +59 -0
- ksadk/kernel/sqlite_session_cleanup.py +84 -0
- ksadk/kernel/sqlite_store.py +232 -622
- ksadk/kernel/store.py +6 -0
- ksadk/kernel/submission_postgres.py +99 -0
- ksadk/kernel/submission_sqlite.py +107 -0
- ksadk/kernel/teams_effects.py +3 -4
- ksadk/kernel/teams_execution_context.py +3 -4
- ksadk/kernel/worker.py +89 -200
- ksadk/kernel/worker_controls.py +112 -27
- ksadk/kernel/worker_interactions.py +343 -47
- ksadk/knowledge_base/__init__.py +1 -1
- ksadk/knowledge_base/client.py +128 -14
- ksadk/knowledge_base/openclaw_bridge.py +58 -0
- ksadk/knowledge_base/service.py +2 -0
- ksadk/mcp_runtime/__init__.py +34 -15
- ksadk/mcp_runtime/_adk.py +14 -0
- ksadk/mcp_runtime/oauth/__init__.py +6 -0
- ksadk/mcp_runtime/oauth/_agent.py +147 -0
- ksadk/mcp_runtime/oauth/_durable_tools.py +208 -0
- ksadk/mcp_runtime/oauth/bootstrap.py +69 -0
- ksadk/mcp_runtime/oauth/client.py +200 -0
- ksadk/mcp_runtime/oauth/code_config.py +90 -0
- ksadk/mcp_runtime/oauth/contract.json +32 -0
- ksadk/mcp_runtime/oauth/contract.py +6 -0
- ksadk/mcp_runtime/oauth/declarations.py +106 -0
- ksadk/mcp_runtime/oauth/http.py +63 -0
- ksadk/mcp_runtime/oauth/kernel.py +717 -0
- ksadk/mcp_runtime/oauth/langgraph.py +402 -0
- ksadk/mcp_runtime/oauth/local/__init__.py +1 -0
- ksadk/mcp_runtime/oauth/local/broker.py +469 -0
- ksadk/mcp_runtime/oauth/local/checkpoint.py +17 -0
- ksadk/mcp_runtime/oauth/local/persistence.py +227 -0
- ksadk/mcp_runtime/oauth/local/protocol.py +390 -0
- ksadk/mcp_runtime/oauth/local/runtime.py +413 -0
- ksadk/mcp_runtime/oauth/local/transport.py +79 -0
- ksadk/mcp_runtime/oauth/runtime_io.py +43 -0
- ksadk/mcp_runtime/oauth/security.py +73 -0
- ksadk/mcp_runtime/oauth/tools.py +396 -0
- ksadk/mcp_runtime/oauth/transport.py +92 -0
- ksadk/memory/adk/long_term_memory.py +1 -2
- ksadk/memory/openclaw_bridge.py +115 -0
- ksadk/memory/providers/local_postgres.py +247 -55
- ksadk/memory/service.py +29 -3
- ksadk/model_gateway/client.py +1 -1
- ksadk/model_proxy/compat.py +22 -0
- ksadk/model_proxy/transform.py +3 -4
- ksadk/plugins/providers/codex.py +37 -2
- ksadk/plugins/providers/harness_tools.py +39 -2
- ksadk/resource_runtime/contracts.py +8 -3
- ksadk/resource_runtime/knowledge.py +1 -1
- ksadk/resource_runtime/managed_projection.py +24 -9
- ksadk/resource_runtime/worker.py +5 -1
- ksadk/runners/_adk_a2a_stream.py +10 -0
- ksadk/runners/_langgraph_answer_contract.py +47 -0
- ksadk/runners/_langgraph_canonical_stream.py +641 -0
- ksadk/runners/_langgraph_checkpoint_binding.py +89 -0
- ksadk/runners/_langgraph_final_answer.py +91 -0
- ksadk/runners/_langgraph_fresh_turn.py +67 -0
- ksadk/runners/_langgraph_interactions.py +199 -0
- ksadk/runners/_langgraph_output.py +69 -0
- ksadk/runners/_langgraph_runner_streams.py +32 -75
- ksadk/runners/_langgraph_state_reader.py +5 -0
- ksadk/runners/_langgraph_wait_cancellation.py +49 -0
- ksadk/runners/_session_identity.py +22 -1
- ksadk/runners/adk_runner.py +13 -3
- ksadk/runners/base_runner.py +21 -0
- ksadk/runners/langgraph_runner.py +128 -108
- ksadk/runners/patch_langchain.py +4 -2
- ksadk/runtime/_langgraph_interaction_adapter.py +333 -0
- ksadk/runtime/_runner_adapter/a2ui_surface.py +194 -22
- ksadk/runtime/_runner_adapter/chunk_mapping.py +688 -0
- ksadk/runtime/_runner_adapter/resume_context.py +64 -0
- ksadk/runtime/_runner_adapter/stream_mapping.py +29 -597
- ksadk/runtime/conversation_execution.py +61 -32
- ksadk/runtime/executor.py +34 -1
- ksadk/runtime/framework_adapters.py +27 -2
- ksadk/runtime/langgraph_checkpoint_view.py +147 -0
- ksadk/runtime/preprocessing.py +9 -1
- ksadk/runtime/runner_adapter.py +77 -37
- ksadk/runtime/session_storage.py +71 -0
- ksadk/sandbox/backends/e2b.py +95 -13
- ksadk/sandbox/backends/local_process.py +68 -4
- ksadk/sandbox/base.py +1 -1
- ksadk/sandbox/diagnostics.py +31 -0
- ksadk/sandbox/e2b_background.py +1768 -0
- ksadk/sandbox/e2b_errors.py +26 -0
- ksadk/sandbox/local_background.py +406 -0
- ksadk/sandbox/local_controls.py +8 -1
- ksadk/server/database_access.py +369 -0
- ksadk/server/database_access_contract.py +222 -0
- ksadk/server/factory.py +125 -3
- ksadk/server/history_deadline.py +20 -4
- ksadk/server/history_page_cache.py +8 -2
- ksadk/server/routes/common.py +11 -1
- ksadk/server/routes/control.py +2 -1
- ksadk/server/routes/database_access.py +17 -0
- ksadk/server/routes/dependencies.py +28 -0
- ksadk/server/routes/interactions.py +106 -0
- ksadk/server/routes/kernel_ingress.py +19 -1
- ksadk/server/routes/local_kernel_control.py +80 -0
- ksadk/server/routes/openai_compat.py +6 -0
- ksadk/server/routes/projection.py +159 -2
- ksadk/server/routes/routers.py +6 -0
- ksadk/server/routes/run.py +30 -1
- ksadk/server/routes/session_identity.py +130 -0
- ksadk/server/routes/sessions.py +326 -312
- ksadk/server/routes/streaming.py +3 -2
- ksadk/server/routes/ui_bootstrap.py +251 -0
- ksadk/server/routes/workspace.py +7 -0
- ksadk/server/static/a2ui/basic-v0_9_1.json +1383 -0
- ksadk/server/static/a2ui/common-types-v0_9.json +305 -0
- ksadk/server/static/a2ui/legacy-seven-components.json +230 -0
- ksadk/server/static/a2ui/manifest.json +86 -0
- ksadk/server/static/a2ui/material-icons-OFL-1.1.txt +93 -0
- ksadk/server/static/assets/{ArtifactsPanel-CILaW-fC.js → ArtifactsPanel-Cdr5C_vM.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-BVrNVtJC.js → CodeBlock-BWRafud9.js} +6 -6
- ksadk/server/static/assets/{MathMessageMarkdown-Dp7c4wWD.js → MathMessageMarkdown-CFKeJIvy.js} +7 -7
- ksadk/server/static/assets/{MermaidBlock-Dxop8Rd7.js → MermaidBlock-BneAGUOd.js} +9 -9
- ksadk/server/static/assets/NativeTerminalPanel-BHI85zDO.js +1 -0
- ksadk/server/static/assets/OfficialA2uiRenderer-BOmT36lJ.js +16 -0
- ksadk/server/static/assets/{abnfDiagram-VCTEODGH-ckWDmOzw.js → abnfDiagram-VCTEODGH-DQvlOsBI.js} +1 -1
- ksadk/server/static/assets/{arc-DqxJede-.js → arc-CGx0e4pN.js} +1 -1
- ksadk/server/static/assets/architecture-7GRP2DOG-CFWjFkDL.js +1 -0
- ksadk/server/static/assets/{architectureDiagram-5GKGNRK7-SEQA4bVi.js → architectureDiagram-5GKGNRK7-WyybcNKX.js} +1 -1
- ksadk/server/static/assets/{blockDiagram-NRAW4CY4-pM0B-6NJ.js → blockDiagram-NRAW4CY4-C9Cx_GVs.js} +1 -1
- ksadk/server/static/assets/{c4Diagram-UCG6FXSJ-m2tuCNVq.js → c4Diagram-UCG6FXSJ-Bh7X3bGr.js} +1 -1
- ksadk/server/static/assets/channel-D6Dp_l74.js +1 -0
- ksadk/server/static/assets/chunk-2Q5K7J3B-CwmjhFYK.js +1 -0
- ksadk/server/static/assets/{chunk-5VM5RSS4-GJHDr9Ww.js → chunk-5VM5RSS4-cP9XupZj.js} +1 -1
- ksadk/server/static/assets/{chunk-F27PBJKO-CbAN45AV.js → chunk-F27PBJKO-Bm77fvR9.js} +1 -1
- ksadk/server/static/assets/{chunk-G27WJ6UU-D5ngbbzF.js → chunk-G27WJ6UU-DDKNPesQ.js} +1 -1
- ksadk/server/static/assets/{chunk-JWPE2WC7-Cc5IwuYC.js → chunk-JWPE2WC7-BqiUDB7s.js} +1 -1
- ksadk/server/static/assets/{chunk-LCL6LL3I-CprgDDdJ.js → chunk-LCL6LL3I-C528mMZy.js} +1 -1
- ksadk/server/static/assets/{chunk-POPQ4Y6H-CDZhSy82.js → chunk-POPQ4Y6H-CzZ9g_Uf.js} +1 -1
- ksadk/server/static/assets/{chunk-RHFEMEQ7-CZchUNro.js → chunk-RHFEMEQ7-CXj4tUZ-.js} +1 -1
- ksadk/server/static/assets/{chunk-SVP7TREG-BVruqk6T.js → chunk-SVP7TREG-BHyd85pS.js} +1 -1
- ksadk/server/static/assets/{chunk-XXDRQBXY-4ld9SxPN.js → chunk-XXDRQBXY-Qe29PHGe.js} +1 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-JH36ORCC-Dmyyk_Vp.js → cose-bilkent-JH36ORCC-maRKgeec.js} +1 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-CBZRVuc4.js +1 -0
- ksadk/server/static/assets/{cynefinDiagram-5FMLGOSQ-BIyq3EJb.js → cynefinDiagram-5FMLGOSQ-CoD0bEvn.js} +1 -1
- ksadk/server/static/assets/{dagre-3AP2YEHR-eBw08Qdk.js → dagre-3AP2YEHR-BkpgQqyW.js} +1 -1
- ksadk/server/static/assets/{dagre-DfvnEf45.js → dagre-BUaTFrYa.js} +1 -1
- ksadk/server/static/assets/{diagram-S7CK7UJ4-CUSrE3Mg.js → diagram-S7CK7UJ4-25HdTbjE.js} +1 -1
- ksadk/server/static/assets/{diagram-UQ7AKVKN-Dq5Zw2gy.js → diagram-UQ7AKVKN-KO-WqOIg.js} +1 -1
- ksadk/server/static/assets/{diagram-VSXAHHWV-DyUHfNwT.js → diagram-VSXAHHWV-B360BkDQ.js} +1 -1
- ksadk/server/static/assets/{diagram-VX7I27RA-CREmM89O.js → diagram-VX7I27RA-COr1Oqsg.js} +1 -1
- ksadk/server/static/assets/{diagram-Z3DM3KII-Dw9zhHUK.js → diagram-Z3DM3KII-CgaKrIwB.js} +1 -1
- ksadk/server/static/assets/{dist-AEv-vXf-.js → dist--HftQyp9.js} +1 -1
- ksadk/server/static/assets/{dist-pq-nD33R.js → dist-B3Jp5r1e.js} +1 -1
- ksadk/server/static/assets/{dist-cxTGfdqx.js → dist-BEbS8Bag.js} +1 -1
- ksadk/server/static/assets/{dist-BX_-FENW.js → dist-BQ116UdZ.js} +1 -1
- ksadk/server/static/assets/{dist-DDSyLEOX.js → dist-BoRn8a_t.js} +1 -1
- ksadk/server/static/assets/{dist-BBsYarrI.js → dist-Brbrdmff.js} +1 -1
- ksadk/server/static/assets/{dist-B8Myiet9.js → dist-Bsuusoi0.js} +1 -1
- ksadk/server/static/assets/{dist-DUxO0R99.js → dist-Bxcu8Ca0.js} +1 -1
- ksadk/server/static/assets/{dist-CVPau3tn.js → dist-By-MVndb.js} +1 -1
- ksadk/server/static/assets/{dist-lOy23y43.js → dist-C9BTMVwS.js} +1 -1
- ksadk/server/static/assets/{dist-C_qdxcSH.js → dist-CBo9AHUv.js} +1 -1
- ksadk/server/static/assets/{dist-bupkyEBZ.js → dist-CR61WJFC.js} +1 -1
- ksadk/server/static/assets/{dist-CHpW1BHj.js → dist-CwnkOyDn.js} +1 -1
- ksadk/server/static/assets/{dist-0uJ4tdx6.js → dist-CxIl4t92.js} +1 -1
- ksadk/server/static/assets/{dist-Cp2PaOMY.js → dist-DKG0OYnk.js} +1 -1
- ksadk/server/static/assets/{dist-BQMrUwdI.js → dist-DSw5Ju6-.js} +1 -1
- ksadk/server/static/assets/{dist-hL5p1til.js → dist-DXOlCAay.js} +1 -1
- ksadk/server/static/assets/{dist-CD4L6ymH.js → dist-DgJ57sRe.js} +1 -1
- ksadk/server/static/assets/{dist-CuR5Bgme.js → dist-DmWw0IXB.js} +1 -1
- ksadk/server/static/assets/{dist-Co68Apq4.js → dist-DzdXSBJb.js} +1 -1
- ksadk/server/static/assets/{dist-B49GzZDb.js → dist-HHvdjADB.js} +1 -1
- ksadk/server/static/assets/{dist-QzbGrED_.js → dist-_0Xgu_07.js} +1 -1
- ksadk/server/static/assets/{ebnfDiagram-PWID7BFC-BS5LdNoR.js → ebnfDiagram-PWID7BFC-DogDP2db.js} +1 -1
- ksadk/server/static/assets/{erDiagram-SSCWMZ5O-Bv1QtiY-.js → erDiagram-SSCWMZ5O-CeBDnUjR.js} +1 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +1 -0
- ksadk/server/static/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +1 -0
- ksadk/server/static/assets/{ganttDiagram-EL5Y4UJY-musi-e0G.js → ganttDiagram-EL5Y4UJY-oIQL3MCp.js} +1 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-BUWSkncI.js +1 -0
- ksadk/server/static/assets/{gitGraphDiagram-WWUBYQGX-DH37EGkG.js → gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js} +1 -1
- ksadk/server/static/assets/index-4g1ndaxW.js +1132 -0
- ksadk/server/static/assets/index-DEVfafsU.css +2 -0
- ksadk/server/static/assets/info-A6RAGUB7-CzJ_YrOs.js +1 -0
- ksadk/server/static/assets/{infoDiagram-RXCK75RN-C1kEtv2y.js → infoDiagram-RXCK75RN-yQRC41Ya.js} +1 -1
- ksadk/server/static/assets/{ishikawaDiagram-5VMMS53U-BCNPyMka.js → ishikawaDiagram-5VMMS53U-BCu4HiwL.js} +1 -1
- ksadk/server/static/assets/{journeyDiagram-EYS64GPL--cDbKnjP.js → journeyDiagram-EYS64GPL-JaqmO73K.js} +1 -1
- ksadk/server/static/assets/{kanban-definition-3QL26DDD-R1rAVw2f.js → kanban-definition-3QL26DDD-DQo4X8NO.js} +1 -1
- ksadk/server/static/assets/{katex-BT-X-V7U.js → katex-t_DWylQw.js} +1 -1
- ksadk/server/static/assets/{linear-DTR631iG.js → linear-DWdnI35B.js} +1 -1
- ksadk/server/static/assets/material-icons-latin-400-normal-kAwBdRge.woff2 +0 -0
- ksadk/server/static/assets/{mermaid-parser.core-DfFzJhX8.js → mermaid-parser.core-BHrT2Pfe.js} +2 -2
- ksadk/server/static/assets/{mindmap-definition-FBJOCRG2-D4by_rmk.js → mindmap-definition-FBJOCRG2-PBVAhZYV.js} +1 -1
- ksadk/server/static/assets/packet-AYTQ26CC-CXoos6fx.js +1 -0
- ksadk/server/static/assets/{pegDiagram-XKGWAZYB-xWXPEh0c.js → pegDiagram-XKGWAZYB-CU_cLfow.js} +1 -1
- ksadk/server/static/assets/pie-WAS4IAKB-CjF9NoIt.js +1 -0
- ksadk/server/static/assets/{pieDiagram-E7YTZNPT-BudBDlCI.js → pieDiagram-E7YTZNPT-B1h0-_pW.js} +1 -1
- ksadk/server/static/assets/{quadrantDiagram-AXDQQJYC-DXZ0PCJF.js → quadrantDiagram-AXDQQJYC-DEMoGo5a.js} +1 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-BQGWs9nw.js +1 -0
- ksadk/server/static/assets/railroad-74A4TZTK-B6znvLUK.js +1 -0
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +1 -0
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +1 -0
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +1 -0
- ksadk/server/static/assets/{railroadDiagram-O6MQD6OU-BdAYRYB8.js → railroadDiagram-O6MQD6OU-BTAob2wg.js} +1 -1
- ksadk/server/static/assets/{requirementDiagram-EFPCY7ZU-CBBmaL70.js → requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js} +1 -1
- ksadk/server/static/assets/{sankeyDiagram-P5KCCOFB-Doc3rdwp.js → sankeyDiagram-P5KCCOFB-DeaTWkur.js} +1 -1
- ksadk/server/static/assets/{sequenceDiagram-WJ2MYXX4-0J8R8hWW.js → sequenceDiagram-WJ2MYXX4-gFQYrsOd.js} +1 -1
- ksadk/server/static/assets/{sizeCapture-X5ZJPWSS-CfFLlWsK.js → sizeCapture-X5ZJPWSS-pGQzddMB.js} +1 -1
- ksadk/server/static/assets/{stateDiagram-HBIQ2CUA-jBwkjtTy.js → stateDiagram-HBIQ2CUA-DmpYOZt1.js} +1 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +1 -0
- ksadk/server/static/assets/{swimlanes-XN3QIQJK-B0WxTQf8.js → swimlanes-XN3QIQJK-BfuSAsrr.js} +1 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +8 -0
- ksadk/server/static/assets/{timeline-definition-24CTP7MA-BfCT_75A.js → timeline-definition-24CTP7MA-CgJwrrxf.js} +1 -1
- ksadk/server/static/assets/treeView-Q6P3EWNA-DtMdDH8N.js +1 -0
- ksadk/server/static/assets/treemap-WGGIJYW6-VoU8QtLZ.js +1 -0
- ksadk/server/static/assets/{vennDiagram-4TSXK5OY-9gX1VMDC.js → vennDiagram-4TSXK5OY-CBSAgXDd.js} +1 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-YWSRB0Zm.js +1 -0
- ksadk/server/static/assets/{wardleyDiagram-VM6X3IG4-sEs_BP6O.js → wardleyDiagram-VM6X3IG4-013TZ2JZ.js} +1 -1
- ksadk/server/static/assets/{xychartDiagram-S5SC5T6Z-Ll4jvUN9.js → xychartDiagram-S5SC5T6Z-u6Frp8xp.js} +1 -1
- ksadk/server/static/index.html +2 -2
- ksadk/server/static/ui-source.json +11 -0
- ksadk/sessions/_local_service_sync.py +146 -5
- ksadk/sessions/_postgres_schema.py +17 -0
- ksadk/sessions/base.py +3 -0
- ksadk/sessions/continuity.py +7 -1
- ksadk/sessions/db_budget.py +14 -12
- ksadk/sessions/history_budget.py +7 -0
- ksadk/sessions/in_memory.py +113 -4
- ksadk/sessions/persistence.py +73 -7
- ksadk/sessions/postgres_service.py +948 -8
- ksadk/sessions/resilience.py +16 -0
- ksadk/sessions/resilient.py +601 -5
- ksadk/sessions/topology.py +9 -2
- ksadk/skills/mcp_server/register.py +471 -415
- ksadk/skills/request_connection.py +188 -0
- ksadk/skills/runtime/backends/e2b.py +52 -12
- ksadk/skills/service_client.py +104 -45
- ksadk/studio/api.py +413 -11
- ksadk/studio/api_contracts.py +7 -3
- ksadk/studio/api_plugin_routes.py +13 -6
- ksadk/studio/authoring_coordinator.py +6 -1
- ksadk/studio/background_output.py +72 -0
- ksadk/studio/build_resolution.py +28 -4
- ksadk/studio/cloud.py +516 -7
- ksadk/studio/cloud_history.py +149 -0
- ksadk/studio/cloud_shared_web.py +32 -3
- ksadk/studio/compiler.py +93 -4
- ksadk/studio/contracts.py +368 -9
- ksadk/studio/dsh_application.py +17 -4
- ksadk/studio/execution_host.py +10 -5
- ksadk/studio/interaction_submission.py +7 -2
- ksadk/studio/model_chat_tools.py +22 -10
- ksadk/studio/model_client.py +41 -11
- ksadk/studio/model_wire_identity.py +24 -0
- ksadk/studio/native_background_command_port.py +97 -0
- ksadk/studio/native_background_connection.py +230 -0
- ksadk/studio/native_background_locator.py +272 -0
- ksadk/studio/native_background_ownership.py +255 -0
- ksadk/studio/native_background_wakeup.py +686 -0
- ksadk/studio/native_browser_port.py +9 -3
- ksadk/studio/native_child_skills.py +4 -0
- ksadk/studio/native_coding_template.py +287 -0
- ksadk/studio/native_command_policy.py +23 -0
- ksadk/studio/native_context_evidence.py +81 -0
- ksadk/studio/native_context_port.py +13 -2
- ksadk/studio/native_directory_observation.py +177 -0
- ksadk/studio/native_final_shape.py +148 -19
- ksadk/studio/native_model_port.py +201 -43
- ksadk/studio/native_planning.py +43 -2
- ksadk/studio/native_product.py +238 -12
- ksadk/studio/native_project_instructions.py +267 -0
- ksadk/studio/native_read_budget.py +21 -3
- ksadk/studio/native_subagent_port.py +125 -2
- ksadk/studio/native_tool_port.py +255 -14
- ksadk/studio/native_verification_presentation.py +13 -3
- ksadk/studio/plugin_kernel_adapter.py +13 -0
- ksadk/studio/plugin_native_activation.py +2 -2
- ksadk/studio/presentation.py +12 -0
- ksadk/studio/project_instruction_trust.py +54 -0
- ksadk/studio/repository.py +1 -1
- ksadk/studio/resource_catalog.py +4 -1
- ksadk/studio/run_activity.py +8 -0
- ksadk/studio/run_service.py +496 -40
- ksadk/studio/scheduler_assistant.py +3 -1
- ksadk/studio/service.py +99 -2
- ksadk/studio/shared_web.py +38 -12
- ksadk/studio/shared_web_response_events.py +32 -5
- ksadk/studio/static/assets/ChannelsPage-Do_mRmVu.js +8 -0
- ksadk/studio/static/assets/{CodeBlock-DMIf4h33-CkufcPYo.js → CodeBlock-DMIf4h33-CsO7rJKv.js} +3 -3
- ksadk/studio/static/assets/{ExecutionTree-v3HexvPo-Bk8wzGSy.js → ExecutionTree-v3HexvPo-BeWoMqA-.js} +1 -1
- ksadk/studio/static/assets/{MathMessageMarkdown-BesSeCYl-DYG1Wzbx.js → MathMessageMarkdown-BesSeCYl-CiB60plG.js} +1 -1
- ksadk/studio/static/assets/{MermaidBlock-H_0qzQDf-BdXtxug_.js → MermaidBlock-H_0qzQDf-oRTZUNRr.js} +3 -3
- ksadk/studio/static/assets/{MessageMarkdown-CwMTvgFj-BeyLyQHu.js → MessageMarkdown-CwMTvgFj-BzEmQkHH.js} +5 -5
- ksadk/studio/static/assets/OfficialA2uiRenderer-DI49Kpxu-BBxfdj3P.js +16 -0
- ksadk/studio/static/assets/{PrismRenderer-5pK6tUdb.js → PrismRenderer-CcrOV6Lf.js} +1 -1
- ksadk/studio/static/assets/TeamsPage-qNVYpcox.js +4 -0
- ksadk/studio/static/assets/{abnfDiagram-VCTEODGH-Bnb1O3tA.js → abnfDiagram-VCTEODGH-BdEjkX5G.js} +1 -1
- ksadk/studio/static/assets/{arc-Pry-7G1_.js → arc-4LNeT6Qr.js} +1 -1
- ksadk/studio/static/assets/architecture-7GRP2DOG-C6BmiLXs.js +1 -0
- ksadk/studio/static/assets/{architectureDiagram-5GKGNRK7-5Zn1gqJv.js → architectureDiagram-5GKGNRK7-nKXkceF2.js} +3 -3
- ksadk/studio/static/assets/{blockDiagram-I7D4REHJ-CLB4L11u.js → blockDiagram-I7D4REHJ-pSawBX0F.js} +1 -1
- ksadk/studio/static/assets/{c4Diagram-7LVT6UL2-BOma_Z_F.js → c4Diagram-7LVT6UL2-D3DGtCIa.js} +1 -1
- ksadk/studio/static/assets/channel-CwBcaXYb.js +1 -0
- ksadk/studio/static/assets/{chunk-2E4U76K2-BFf_huql.js → chunk-2E4U76K2-CfUBZPB8.js} +2 -2
- ksadk/studio/static/assets/chunk-2Q5K7J3B-B9fZb2AW.js +1 -0
- ksadk/studio/static/assets/{chunk-2ZTRR5NV-C2qZJila.js → chunk-2ZTRR5NV-63jTqPgP.js} +1 -1
- ksadk/studio/static/assets/{chunk-3Z5EZCMW-DMniOlPd.js → chunk-3Z5EZCMW-CLzTC-ds.js} +1 -1
- ksadk/studio/static/assets/{chunk-4HAMMTFA-DVtDP4rm.js → chunk-4HAMMTFA--k1euiK8.js} +3 -3
- ksadk/studio/static/assets/{chunk-5V3GS4D5-i-ZDOEnP.js → chunk-5V3GS4D5--NT8dMSC.js} +1 -1
- ksadk/studio/static/assets/{chunk-5VM5RSS4-ZNzvKenW.js → chunk-5VM5RSS4-B4EX-xPG.js} +2 -2
- ksadk/studio/static/assets/{chunk-6AZGARVD-BB6FqMl-.js → chunk-6AZGARVD-BxyCuIKr.js} +1 -1
- ksadk/studio/static/assets/{chunk-6EIED4P4-DdUJkP0f.js → chunk-6EIED4P4-BqAnqs6L.js} +1 -1
- ksadk/studio/static/assets/{chunk-6K3QC6MW-CqVsVn-y.js → chunk-6K3QC6MW-DqKCc1_c.js} +1 -1
- ksadk/studio/static/assets/{chunk-6TQVIW2G-DKlLbNIP.js → chunk-6TQVIW2G-NQp6TssR.js} +1 -1
- ksadk/studio/static/assets/{chunk-747NJXEK-BFkZPlab.js → chunk-747NJXEK-CFf3ol0D.js} +1 -1
- ksadk/studio/static/assets/{chunk-75Z2AOVW-BZNhM4vB.js → chunk-75Z2AOVW-DpzsVI3p.js} +1 -1
- ksadk/studio/static/assets/chunk-CLGD4ZFX-BiEFihjn.js +1 -0
- ksadk/studio/static/assets/{chunk-DU6HZSFF-CpEZCUgg.js → chunk-DU6HZSFF-HbWKkMwX.js} +3 -3
- ksadk/studio/static/assets/{chunk-F27PBJKO-D7pvKf0C.js → chunk-F27PBJKO-BY9pwz0W.js} +1 -1
- ksadk/studio/static/assets/{chunk-FOHPRMQF-DHwB1DNv.js → chunk-FOHPRMQF-BAABtQ6R.js} +5 -5
- ksadk/studio/static/assets/{chunk-GMAD6QVW-DE_8H717.js → chunk-GMAD6QVW-C-Lw1ag9.js} +1 -1
- ksadk/studio/static/assets/{chunk-GVQU2GXP-BfEB0lNv.js → chunk-GVQU2GXP-CCUMaVF8.js} +1 -1
- ksadk/studio/static/assets/{chunk-I5DQTOEV-Hm2LfiYI.js → chunk-I5DQTOEV-DpUJ7zEH.js} +1 -1
- ksadk/studio/static/assets/{chunk-ICYGCRZG-749o-pGJ.js → chunk-ICYGCRZG-CknVx2uG.js} +1 -1
- ksadk/studio/static/assets/{chunk-IH6LHLGP-CC6I9F3i.js → chunk-IH6LHLGP-BJ6nT6RF.js} +1 -1
- ksadk/studio/static/assets/{chunk-IMKFNOWR-D38axYOR.js → chunk-IMKFNOWR-CTelL5KO.js} +1 -1
- ksadk/studio/static/assets/{chunk-JWPE2WC7-DVXcaiue.js → chunk-JWPE2WC7-CMg2kMrr.js} +1 -1
- ksadk/studio/static/assets/{chunk-KI3K4JFJ-Rma-0k_M.js → chunk-KI3K4JFJ-B1SKa0PC.js} +1 -1
- ksadk/studio/static/assets/{chunk-L3NEJ4N5-Dq5xn7aL.js → chunk-L3NEJ4N5-C8A22muD.js} +1 -1
- ksadk/studio/static/assets/{chunk-LNGE3PJU-DWpGwHrW.js → chunk-LNGE3PJU-D_NJe87O.js} +1 -1
- ksadk/studio/static/assets/{chunk-OSK3NFVY-DiCQjx9b.js → chunk-OSK3NFVY-DFHvKoNt.js} +1 -1
- ksadk/studio/static/assets/{chunk-OUJLGHUK-D0j2JRSg.js → chunk-OUJLGHUK-DkHSrVKj.js} +1 -1
- ksadk/studio/static/assets/{chunk-P2QGCYS3-VdhKmfYq.js → chunk-P2QGCYS3-C3nH7MEr.js} +1 -1
- ksadk/studio/static/assets/{chunk-POPQ4Y6H-C1_rzO5M.js → chunk-POPQ4Y6H-CLm6A2JW.js} +1 -1
- ksadk/studio/static/assets/{chunk-PWAF6VOD-B45HvflI.js → chunk-PWAF6VOD-BmVQq92D.js} +1 -1
- ksadk/studio/static/assets/{chunk-SHT3W25Y-DsCFnRVE.js → chunk-SHT3W25Y-cETj_Yg7.js} +1 -1
- ksadk/studio/static/assets/{chunk-SVP7TREG-DljApgRX.js → chunk-SVP7TREG-hm4Ur8KN.js} +1 -1
- ksadk/studio/static/assets/{chunk-TICWLB2K-DWqRtyqa.js → chunk-TICWLB2K-BuVjFGjc.js} +1 -1
- ksadk/studio/static/assets/{chunk-TLUHSLCS-DUeGgnD5.js → chunk-TLUHSLCS-7mZ4xr0q.js} +2 -2
- ksadk/studio/static/assets/{chunk-UY3FDG6J-CnmaAkG5.js → chunk-UY3FDG6J-2nV2i5mW.js} +1 -1
- ksadk/studio/static/assets/{chunk-XHIXRSVI-BFQ6B8BE.js → chunk-XHIXRSVI-BIR36bKX.js} +1 -1
- ksadk/studio/static/assets/chunk-XXDRQBXY-rafYnJzG.js +1 -0
- ksadk/studio/static/assets/classDiagram-ZZMXUADV-DdyoXyMk.js +1 -0
- ksadk/studio/static/assets/classDiagram-v2-VYDZK3BY-DdyoXyMk.js +1 -0
- ksadk/studio/static/assets/{cose-bilkent-JH36ORCC-om8AY0Mc.js → cose-bilkent-JH36ORCC-B9Ubz7rk.js} +1 -1
- ksadk/studio/static/assets/{createLucideIcon-DR0LGTP5.js → createLucideIcon-CTD6_IjT.js} +1 -1
- ksadk/studio/static/assets/cynefin-OW5HDTMX-BVS4hy6V.js +1 -0
- ksadk/studio/static/assets/{cynefinDiagram-5FMLGOSQ-6BrmK52S.js → cynefinDiagram-5FMLGOSQ-CKrgw1wI.js} +1 -1
- ksadk/studio/static/assets/{cytoscape.esm-CGd-uY3x.js → cytoscape.esm-Jip0ihto.js} +16 -16
- ksadk/studio/static/assets/{dagre-GXQ25YYZ-buZBRlwz.js → dagre-GXQ25YYZ-NjDjs3Kl.js} +1 -1
- ksadk/studio/static/assets/{dagre-PrKaheQc.js → dagre-YnTFOVV4.js} +1 -1
- ksadk/studio/static/assets/{diagram-S7CK7UJ4-C6aH78c4.js → diagram-S7CK7UJ4-C6X87QRZ.js} +1 -1
- ksadk/studio/static/assets/{diagram-UQ7AKVKN-DY_tQ6C_.js → diagram-UQ7AKVKN-Xf2JVuyK.js} +1 -1
- ksadk/studio/static/assets/{diagram-VSXAHHWV-DX9p5cQT.js → diagram-VSXAHHWV-CUZlU7Dr.js} +1 -1
- ksadk/studio/static/assets/{diagram-VX7I27RA-DB2WSH8X.js → diagram-VX7I27RA-BOcfFxfe.js} +1 -1
- ksadk/studio/static/assets/{diagram-Z3DM3KII-Ce1BJwHE.js → diagram-Z3DM3KII-1zrr7ezR.js} +1 -1
- ksadk/studio/static/assets/{dist-v5Q1xZ2K.js → dist-Brlz61T5.js} +1 -1
- ksadk/studio/static/assets/{ebnfDiagram-PWID7BFC-Daukxwqf.js → ebnfDiagram-PWID7BFC-C1LymnKg.js} +1 -1
- ksadk/studio/static/assets/{erDiagram-RLTQ6QDP-CGthTMmJ.js → erDiagram-RLTQ6QDP-Dm0YWPea.js} +1 -1
- ksadk/studio/static/assets/eventmodeling-NTZA5JFV-D9gMNzTL.js +1 -0
- ksadk/studio/static/assets/flowDiagram-HODETNUW-NYJgBJQu.js +1 -0
- ksadk/studio/static/assets/{ganttDiagram-EL5Y4UJY-BfoAZW9X.js → ganttDiagram-EL5Y4UJY-uJ27IKEw.js} +1 -1
- ksadk/studio/static/assets/gitGraph-4MIJSDKK-DQVCMicu.js +1 -0
- ksadk/studio/static/assets/{gitGraphDiagram-WWUBYQGX-S985OIJF.js → gitGraphDiagram-WWUBYQGX-mtpvi7ne.js} +3 -3
- ksadk/studio/static/assets/index-Cp9Unfkn.css +2 -0
- ksadk/studio/static/assets/index-HepnaEeR.js +1152 -0
- ksadk/studio/static/assets/{index.dom-BQenBtFm.js → index.dom-DSf_jcX2.js} +1 -1
- ksadk/studio/static/assets/info-A6RAGUB7-CMrsF9SP.js +1 -0
- ksadk/studio/static/assets/{infoDiagram-27XIBGKW-CO3W8tFn.js → infoDiagram-27XIBGKW-Hqrd2vbU.js} +1 -1
- ksadk/studio/static/assets/{ishikawaDiagram-5VMMS53U-BUGEl8cO.js → ishikawaDiagram-5VMMS53U-BB7nm3Dk.js} +1 -1
- ksadk/studio/static/assets/{journeyDiagram-3NMN7TZE-Ch2ZYxvr.js → journeyDiagram-3NMN7TZE-BXbRt7Ps.js} +1 -1
- ksadk/studio/static/assets/{kanban-definition-UXKFOSKX-Da-Fp4vC.js → kanban-definition-UXKFOSKX-2EtAxRbw.js} +1 -1
- ksadk/studio/static/assets/{katex-DhON-x74.js → katex-K_8DQ5UN.js} +1 -1
- ksadk/studio/static/assets/{line-BDaeq300.js → line-C4h80pWP.js} +1 -1
- ksadk/studio/static/assets/{linear-DmucvK78.js → linear-DCteYK3U.js} +1 -1
- ksadk/studio/static/assets/{mermaid-parser.core-Cj5mYdBi.js → mermaid-parser.core-TWhr-wg2.js} +2 -2
- ksadk/studio/static/assets/{mindmap-definition-YA3MSWOX-CvlsVQ38.js → mindmap-definition-YA3MSWOX-BC7jpEOt.js} +1 -1
- ksadk/studio/static/assets/{ordinal-BDEzSJ7C.js → ordinal-BXUrfsNY.js} +1 -1
- ksadk/studio/static/assets/packet-AYTQ26CC-BdMfjW7Z.js +1 -0
- ksadk/studio/static/assets/{pegDiagram-XKGWAZYB-BuHuNgT5.js → pegDiagram-XKGWAZYB-C-ZzWopk.js} +1 -1
- ksadk/studio/static/assets/pie-WAS4IAKB-B06bKgAM.js +1 -0
- ksadk/studio/static/assets/{pieDiagram-E7YTZNPT-DlrWiSOv.js → pieDiagram-E7YTZNPT-DGDL1XJp.js} +1 -1
- ksadk/studio/static/assets/{quadrantDiagram-AXDQQJYC-BA3hpUZM.js → quadrantDiagram-AXDQQJYC-DAPa64vy.js} +1 -1
- ksadk/studio/static/assets/radar-RG4KPBEZ-4lhecdYg.js +1 -0
- ksadk/studio/static/assets/railroad-74A4TZTK-CBTdV2Xq.js +1 -0
- ksadk/studio/static/assets/railroad-abnf-HS5TGJTU-D4HzgxJY.js +1 -0
- ksadk/studio/static/assets/railroad-ebnf-LZEXJU2U-D-qRzoh8.js +1 -0
- ksadk/studio/static/assets/railroad-peg-WCYAUIDC-DYA99dLv.js +1 -0
- ksadk/studio/static/assets/{railroadDiagram-O6MQD6OU-BxpAazym.js → railroadDiagram-O6MQD6OU-CkH0b7UT.js} +1 -1
- ksadk/studio/static/assets/{react-vendor-BNmTiJ-I.js → react-vendor-CTyAWUMQ.js} +1 -1
- ksadk/studio/static/assets/{requirementDiagram-BXWQKSXE-E-Ge0FcV.js → requirementDiagram-BXWQKSXE-BgZ0H8ni.js} +2 -2
- ksadk/studio/static/assets/rolldown-runtime-cO0ylGnt.js +1 -0
- ksadk/studio/static/assets/{sankeyDiagram-P5KCCOFB-CA6YKhQ3.js → sankeyDiagram-P5KCCOFB-BgqqGK6v.js} +1 -1
- ksadk/studio/static/assets/{sequenceDiagram-WJ2MYXX4-CcElXGg4.js → sequenceDiagram-WJ2MYXX4-CbQE1ava.js} +1 -1
- ksadk/studio/static/assets/{sizeCapture-INFHLROL-B0uUizjq.js → sizeCapture-INFHLROL-BtEJ4_JN.js} +1 -1
- ksadk/studio/static/assets/{src-B6xuSHsQ.js → src-DSHesKRm.js} +1 -1
- ksadk/studio/static/assets/{stateDiagram-D77RDMKH-DdXZOFqY.js → stateDiagram-D77RDMKH-D9uG2y8U.js} +1 -1
- ksadk/studio/static/assets/stateDiagram-v2-MP3YSRHH-2pITMnQn.js +1 -0
- ksadk/studio/static/assets/{swimlanes-42K2YHIH-NtgEEHLY.js → swimlanes-42K2YHIH-B0QgwqLd.js} +1 -1
- ksadk/studio/static/assets/swimlanesDiagram-VR7AAH4N-TXD08-JZ.js +8 -0
- ksadk/studio/static/assets/{timeline-definition-24CTP7MA-CIuYhNy3.js → timeline-definition-24CTP7MA-tbRyDWb4.js} +1 -1
- ksadk/studio/static/assets/treeView-Q6P3EWNA-NawrivXx.js +1 -0
- ksadk/studio/static/assets/treemap-WGGIJYW6-DabVcIU4.js +1 -0
- ksadk/studio/static/assets/{vennDiagram-4TSXK5OY-7HbApbrv.js → vennDiagram-4TSXK5OY-Xjhys4e4.js} +1 -1
- ksadk/studio/static/assets/wardley-WFR3VGLG-BrU5uhdd.js +1 -0
- ksadk/studio/static/assets/{wardleyDiagram-VM6X3IG4-CMJiaedy.js → wardleyDiagram-VM6X3IG4--sd605zd.js} +1 -1
- ksadk/studio/static/assets/{xychartDiagram-S5SC5T6Z-BdgtMvW2.js → xychartDiagram-S5SC5T6Z-B3XzcsnZ.js} +1 -1
- ksadk/studio/static/index.html +9 -9
- ksadk/studio/static/ui-source.json +11 -0
- ksadk/studio/teams_installation.py +1 -1
- ksadk/studio/templates.py +33 -3
- ksadk/toolsets/__init__.py +14 -1
- ksadk/toolsets/sandbox.py +303 -7
- ksadk/toolsets/workspace.py +17 -10
- ksadk/toolsets/workspace_editing.py +40 -0
- ksadk/toolsets/workspace_model_observation.py +6 -1
- ksadk/tracing/__init__.py +10 -1
- ksadk/tracing/routed.py +416 -0
- ksadk/tracing/setup.py +58 -3
- ksadk/version.py +1 -1
- ksadk_runtime_common/memory_backend/manifest.py +1 -1
- ksadk_runtime_common/memory_backend/providers/ksmem.py +60 -0
- ksadk_runtime_common/memory_backend/providers/lancedb.py +1 -2
- ksadk_runtime_common/memory_backend/providers/mem0.py +1 -0
- ksadk_runtime_common/memory_backend/registry.py +2 -0
- ksadk_runtime_common/memory_backend/render.py +1 -1
- ksadk_runtime_common/schemas/memory_backend_manifest.schema.json +37 -12
- ksadk_runtime_common/schemas/runtime_event_v2.json +2 -1
- ksadk/server/static/assets/NativeTerminalPanel-Cjjz8B30.js +0 -1
- ksadk/server/static/assets/architecture-7GRP2DOG-pn_DuLy6.js +0 -1
- ksadk/server/static/assets/channel-fySsnkft.js +0 -1
- ksadk/server/static/assets/chunk-2Q5K7J3B-BheGxKRQ.js +0 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DSfLtNYm.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DSfLtNYm.js +0 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-PFWIGtvA.js +0 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-DsM4upQX.js +0 -1
- ksadk/server/static/assets/flowDiagram-A5DVABFB-D5NA16k9.js +0 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-DUCVz-ih.js +0 -1
- ksadk/server/static/assets/index-CZdkAvsv.js +0 -244
- ksadk/server/static/assets/index-CvXdHgF3.css +0 -2
- ksadk/server/static/assets/info-A6RAGUB7-rw0ZNHZp.js +0 -1
- ksadk/server/static/assets/packet-AYTQ26CC-Ca4Hvki9.js +0 -1
- ksadk/server/static/assets/pie-WAS4IAKB-hwiz6fbw.js +0 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-BR1oZXLM.js +0 -1
- ksadk/server/static/assets/railroad-74A4TZTK-DfgEISfX.js +0 -1
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-CWOC3rdk.js +0 -1
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CiRvHCLY.js +0 -1
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-DSDDyJ2f.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Cw1fPb5w.js +0 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-Cc3JMBAF.js +0 -8
- ksadk/server/static/assets/treeView-Q6P3EWNA-C05SJHxo.js +0 -1
- ksadk/server/static/assets/treemap-WGGIJYW6-BqNLAhc3.js +0 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-DokNktqB.js +0 -1
- ksadk/studio/static/assets/ChannelsPage-xX5HlMId.js +0 -8
- ksadk/studio/static/assets/TeamsPage-CCaaGaVp.js +0 -3
- ksadk/studio/static/assets/architecture-7GRP2DOG-BMOPAkUC.js +0 -1
- ksadk/studio/static/assets/channel-r8itPEik.js +0 -1
- ksadk/studio/static/assets/chunk-2Q5K7J3B-C1jixKkw.js +0 -1
- ksadk/studio/static/assets/chunk-CLGD4ZFX-D-GTtyKs.js +0 -1
- ksadk/studio/static/assets/chunk-XXDRQBXY-DqAYeljN.js +0 -1
- ksadk/studio/static/assets/classDiagram-ZZMXUADV-DjeMNJmu.js +0 -1
- ksadk/studio/static/assets/classDiagram-v2-VYDZK3BY-DjeMNJmu.js +0 -1
- ksadk/studio/static/assets/cynefin-OW5HDTMX-7tP7QfM3.js +0 -1
- ksadk/studio/static/assets/eventmodeling-NTZA5JFV-BR2FzK4R.js +0 -1
- ksadk/studio/static/assets/flowDiagram-HODETNUW-CZ1tEenp.js +0 -1
- ksadk/studio/static/assets/gitGraph-4MIJSDKK-DYlXv_yJ.js +0 -1
- ksadk/studio/static/assets/index-C7DNDik2.css +0 -2
- ksadk/studio/static/assets/index-Cy68gTlH.js +0 -265
- ksadk/studio/static/assets/info-A6RAGUB7-BlU-8_xu.js +0 -1
- ksadk/studio/static/assets/packet-AYTQ26CC-BSJEH9Lb.js +0 -1
- ksadk/studio/static/assets/pie-WAS4IAKB-qxv01Y8W.js +0 -1
- ksadk/studio/static/assets/radar-RG4KPBEZ-B6h6pWOs.js +0 -1
- ksadk/studio/static/assets/railroad-74A4TZTK-CGtTWdGc.js +0 -1
- ksadk/studio/static/assets/railroad-abnf-HS5TGJTU-Cq7y22IA.js +0 -1
- ksadk/studio/static/assets/railroad-ebnf-LZEXJU2U-V0aQVv9m.js +0 -1
- ksadk/studio/static/assets/railroad-peg-WCYAUIDC-BQiIsX_p.js +0 -1
- ksadk/studio/static/assets/rolldown-runtime-hePW80VL.js +0 -1
- ksadk/studio/static/assets/stateDiagram-v2-MP3YSRHH-CJbOM-QK.js +0 -1
- ksadk/studio/static/assets/swimlanesDiagram-VR7AAH4N-D-AVlW8B.js +0 -8
- ksadk/studio/static/assets/treeView-Q6P3EWNA-BTTYcvrF.js +0 -1
- ksadk/studio/static/assets/treemap-WGGIJYW6-Cg7tyfH8.js +0 -1
- ksadk/studio/static/assets/wardley-WFR3VGLG-C6N1rULY.js +0 -1
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.7.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.7.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.7.dist-info}/top_level.txt +0 -0
- /ksadk/studio/static/assets/{array-BifhSqXX.js → array-mTkv7xdZ.js} +0 -0
- /ksadk/studio/static/assets/{chunk-Y2CYZVJY-DsF7k-Jl.js → chunk-Y2CYZVJY-C72YQVBQ.js} +0 -0
- /ksadk/studio/static/assets/{clsx-DB0hHKMi.js → clsx-BE-4uLAX.js} +0 -0
- /ksadk/studio/static/assets/{defaultLocale-BFoDCU3G.js → defaultLocale-YBltSZ3l.js} +0 -0
- /ksadk/studio/static/assets/{graphlib-DS17s2tU.js → graphlib-CYZB3_li.js} +0 -0
- /ksadk/studio/static/assets/{init-C-OQMol4.js → init-Ccnd9r3c.js} +0 -0
- /ksadk/studio/static/assets/{path-fybaL0A-.js → path-BfzAkHoX.js} +0 -0
- /ksadk/studio/static/assets/{preload-helper-CO68xz6u.js → preload-helper-2TpOpXko.js} +0 -0
- /ksadk/studio/static/assets/{presentation-yYw7xK60-BmcZriri.js → presentation-yYw7xK60-B7PYgYAE.js} +0 -0
- /ksadk/studio/static/assets/{rolldown-runtime-Dy4uBu1J-DK3Fl9T5.js → rolldown-runtime-Dy4uBu1J-CmRlGT1x.js} +0 -0
- /ksadk/studio/static/assets/{rough.esm-Dy-Kn_BL.js → rough.esm-BF6Sy8cM.js} +0 -0
|
@@ -47,12 +47,6 @@ from ksadk.sessions.db_budget import (
|
|
|
47
47
|
from ksadk.sessions.errors import HistoryProjectionBudgetExceeded, SessionBackendUnavailable
|
|
48
48
|
from ksadk.sessions.history_budget import CURRENT_HISTORY_READ_BUDGET
|
|
49
49
|
|
|
50
|
-
from ksadk.sessions._postgres_history_read import _HistoryEventWindow
|
|
51
|
-
|
|
52
|
-
from ksadk.sessions._postgres_history_read import _PostgresHistoryReadMixin
|
|
53
|
-
|
|
54
|
-
from ksadk.sessions._postgres_checkpoint_read import _PostgresCheckpointReadMixin
|
|
55
|
-
|
|
56
50
|
logger = logging.getLogger(__name__)
|
|
57
51
|
|
|
58
52
|
|
|
@@ -95,7 +89,7 @@ class _TimedConnection:
|
|
|
95
89
|
async def fetch_replay(self, query: str, *args: Any, batch_size: int = 32) -> Any:
|
|
96
90
|
"""Fetch complete replay through a fixed cursor with bounded commands.
|
|
97
91
|
|
|
98
|
-
Full context can exceed a history page's
|
|
92
|
+
Full context can exceed a history page's per-command SQL budget in
|
|
99
93
|
aggregate. Small cursor batches have a dedicated command budget; the
|
|
100
94
|
whole replay has a separate deadline and cancellation rolls back.
|
|
101
95
|
"""
|
|
@@ -111,6 +105,7 @@ class _TimedConnection:
|
|
|
111
105
|
self._connection, self._replay_sql_seconds, self._cleanup_seconds,
|
|
112
106
|
)
|
|
113
107
|
while True:
|
|
108
|
+
started = asyncio.get_running_loop().time()
|
|
114
109
|
batch = await bounded_driver_call(
|
|
115
110
|
cursor.fetch(batch_size, timeout=self._replay_sql_seconds),
|
|
116
111
|
self._connection, self._replay_sql_seconds, self._cleanup_seconds,
|
|
@@ -118,6 +113,20 @@ class _TimedConnection:
|
|
|
118
113
|
rows.extend(batch)
|
|
119
114
|
if len(batch) < batch_size:
|
|
120
115
|
return rows
|
|
116
|
+
# A run may contain many full graph-state snapshots.
|
|
117
|
+
# Adapt before the next fetch so a single command does
|
|
118
|
+
# not transfer dozens of those indivisible JSON bodies.
|
|
119
|
+
body_bytes = sum(
|
|
120
|
+
len(value.encode("utf-8")) if isinstance(value, str)
|
|
121
|
+
else len(value) if isinstance(value, bytes) else 16
|
|
122
|
+
for row in batch for value in row.values()
|
|
123
|
+
)
|
|
124
|
+
byte_rows = max(1, batch_size * (256 * 1024) // max(1, body_bytes))
|
|
125
|
+
elapsed = asyncio.get_running_loop().time() - started
|
|
126
|
+
time_rows = max(1, int(
|
|
127
|
+
batch_size * (self._replay_sql_seconds * 0.5) / max(0.001, elapsed)
|
|
128
|
+
))
|
|
129
|
+
batch_size = min(64, batch_size * 2, byte_rows, time_rows)
|
|
121
130
|
|
|
122
131
|
async def fetch_history_page(
|
|
123
132
|
self, query: str, *args: Any, batch_size: int = 8,
|
|
@@ -218,7 +227,30 @@ class _TimedConnection:
|
|
|
218
227
|
raise
|
|
219
228
|
|
|
220
229
|
|
|
221
|
-
class
|
|
230
|
+
class _HistoryEventWindow(list[SessionEvent]):
|
|
231
|
+
"""Internal short-page proof: a byte-limited page may still have more rows."""
|
|
232
|
+
def __init__(self, events, *, source_exhausted: bool):
|
|
233
|
+
super().__init__(events)
|
|
234
|
+
self.source_exhausted = source_exhausted
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _message_projection_filter(clauses: list[str], prefix: str = "") -> None:
|
|
238
|
+
from ksadk.sessions.history_budget import CURRENT_MESSAGE_PROJECTION
|
|
239
|
+
|
|
240
|
+
if not CURRENT_MESSAGE_PROJECTION.get():
|
|
241
|
+
return
|
|
242
|
+
event = f"{prefix}content_json->'runtime_event'"
|
|
243
|
+
# Only the opaque LangGraph state channel is omitted. Protocol-bearing
|
|
244
|
+
# data (including A2UI) and all readable/tool/control facts remain visible.
|
|
245
|
+
clauses.append("NOT ("
|
|
246
|
+
f"COALESCE(({event})->>'item_kind','')='data' AND "
|
|
247
|
+
f"COALESCE(({event})->'source'->>'framework','')='langgraph' AND "
|
|
248
|
+
f"COALESCE(({event})->'source'->'metadata'->>'channel','')='values' AND "
|
|
249
|
+
f"COALESCE(({event})->'source'->>'protocol','')='' AND "
|
|
250
|
+
f"COALESCE(({event})->'source'->'metadata'->>'protocol','')='')")
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
class PostgresSessionService(_PostgresToolReceiptMixin, _PostgresSchemaMixin, BaseSessionService):
|
|
222
254
|
# Its get/list/query/count operations never execute Agent or tool effects.
|
|
223
255
|
_retry_safe_reads = True
|
|
224
256
|
storage_capabilities = CANONICAL_EVENT_STORAGE_CAPABILITIES
|
|
@@ -445,6 +477,20 @@ class PostgresSessionService(_PostgresCheckpointReadMixin, _PostgresHistoryReadM
|
|
|
445
477
|
include_events=False,
|
|
446
478
|
)
|
|
447
479
|
|
|
480
|
+
async def missing_session_ids(self, session_ids: set[str]) -> set[str]:
|
|
481
|
+
"""Check a split Kernel's candidates against this namespace in one snapshot."""
|
|
482
|
+
if not session_ids:
|
|
483
|
+
return set()
|
|
484
|
+
await self._ensure_schema()
|
|
485
|
+
async with self._connection() as connection:
|
|
486
|
+
rows = await connection.fetch(
|
|
487
|
+
f"""SELECT id FROM unnest($2::text[]) AS candidate(id)
|
|
488
|
+
WHERE NOT EXISTS (SELECT FROM {KSADK_PG_SESSIONS_TABLE} s
|
|
489
|
+
WHERE s.namespace=$1 AND s.id=candidate.id)""",
|
|
490
|
+
self.namespace, list(session_ids),
|
|
491
|
+
)
|
|
492
|
+
return {row["id"] for row in rows}
|
|
493
|
+
|
|
448
494
|
async def get_session_header(self, session_id: str) -> Optional[Session]:
|
|
449
495
|
"""History authorization/epoch fields without reading the state blob."""
|
|
450
496
|
await self._ensure_schema()
|
|
@@ -587,6 +633,18 @@ class PostgresSessionService(_PostgresCheckpointReadMixin, _PostgresHistoryReadM
|
|
|
587
633
|
@_write_deadline
|
|
588
634
|
async def delete_session(self, session_id: str) -> bool:
|
|
589
635
|
await self._ensure_schema()
|
|
636
|
+
# Kernel writers lock their work before appending a Session event.
|
|
637
|
+
# PostgreSQL can abort either writer on a concurrent delete. Restart
|
|
638
|
+
# only an explicitly aborted transaction, within the operation budget.
|
|
639
|
+
while True:
|
|
640
|
+
try:
|
|
641
|
+
return await self._delete_session_transaction(session_id)
|
|
642
|
+
except Exception as exc:
|
|
643
|
+
if getattr(exc, "sqlstate", None) not in {"40P01", "40001"}:
|
|
644
|
+
raise
|
|
645
|
+
await asyncio.sleep(0.01)
|
|
646
|
+
|
|
647
|
+
async def _delete_session_transaction(self, session_id: str) -> bool:
|
|
590
648
|
async with self._connection(write=True) as connection:
|
|
591
649
|
async with connection.transaction():
|
|
592
650
|
await self._set_lock_timeout(connection)
|
|
@@ -861,6 +919,7 @@ class PostgresSessionService(_PostgresCheckpointReadMixin, _PostgresHistoryReadM
|
|
|
861
919
|
) -> list[SessionEvent]:
|
|
862
920
|
await self._ensure_schema()
|
|
863
921
|
conditions = ["namespace = $1", "session_id = $2", "invocation_id = $3"]
|
|
922
|
+
_message_projection_filter(conditions)
|
|
864
923
|
params: list[Any] = [self.namespace, session_id, invocation_id]
|
|
865
924
|
if after_seq_id is not None:
|
|
866
925
|
params.append(after_seq_id)
|
|
@@ -881,6 +940,808 @@ class PostgresSessionService(_PostgresCheckpointReadMixin, _PostgresHistoryReadM
|
|
|
881
940
|
)
|
|
882
941
|
return [self._event_from_row(row) for row in rows]
|
|
883
942
|
|
|
943
|
+
async def get_events(
|
|
944
|
+
self,
|
|
945
|
+
session_id: str,
|
|
946
|
+
offset: Optional[int] = None,
|
|
947
|
+
limit: Optional[int] = None,
|
|
948
|
+
after_seq_id: Optional[int] = None,
|
|
949
|
+
before_seq_id: Optional[int] = None,
|
|
950
|
+
) -> list[SessionEvent]:
|
|
951
|
+
await self._ensure_schema()
|
|
952
|
+
# seq 过滤先应用,再对结果集应用"最新 N 条" offset/limit 语义。
|
|
953
|
+
conditions = ["namespace = $1", "session_id = $2"]
|
|
954
|
+
_message_projection_filter(conditions)
|
|
955
|
+
params: list[Any] = [self.namespace, session_id]
|
|
956
|
+
if after_seq_id is not None:
|
|
957
|
+
params.append(after_seq_id)
|
|
958
|
+
conditions.append(f"seq_id > ${len(params)}")
|
|
959
|
+
if before_seq_id is not None:
|
|
960
|
+
params.append(before_seq_id)
|
|
961
|
+
conditions.append(f"seq_id < ${len(params)}")
|
|
962
|
+
where_clause = " AND ".join(conditions)
|
|
963
|
+
async with self._connection() as connection:
|
|
964
|
+
if limit is not None:
|
|
965
|
+
params.extend([limit, offset or 0])
|
|
966
|
+
limit_param = len(params) - 1
|
|
967
|
+
offset_param = len(params)
|
|
968
|
+
query = f"""
|
|
969
|
+
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
970
|
+
state_delta_json, seq_id, invocation_id, metadata_json
|
|
971
|
+
FROM (
|
|
972
|
+
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
973
|
+
state_delta_json, seq_id, invocation_id, metadata_json
|
|
974
|
+
FROM {KSADK_PG_EVENTS_TABLE}
|
|
975
|
+
WHERE {where_clause}
|
|
976
|
+
ORDER BY seq_id DESC
|
|
977
|
+
LIMIT ${limit_param} OFFSET ${offset_param}
|
|
978
|
+
) AS latest_events
|
|
979
|
+
ORDER BY seq_id ASC
|
|
980
|
+
"""
|
|
981
|
+
elif offset is not None:
|
|
982
|
+
params.append(offset)
|
|
983
|
+
offset_param = len(params)
|
|
984
|
+
query = f"""
|
|
985
|
+
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
986
|
+
state_delta_json, seq_id, invocation_id, metadata_json
|
|
987
|
+
FROM (
|
|
988
|
+
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
989
|
+
state_delta_json, seq_id, invocation_id, metadata_json
|
|
990
|
+
FROM {KSADK_PG_EVENTS_TABLE}
|
|
991
|
+
WHERE {where_clause}
|
|
992
|
+
ORDER BY seq_id DESC
|
|
993
|
+
OFFSET ${offset_param}
|
|
994
|
+
) AS latest_events
|
|
995
|
+
ORDER BY seq_id ASC
|
|
996
|
+
"""
|
|
997
|
+
else:
|
|
998
|
+
query = f"""
|
|
999
|
+
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
1000
|
+
state_delta_json, seq_id, invocation_id, metadata_json
|
|
1001
|
+
FROM {KSADK_PG_EVENTS_TABLE}
|
|
1002
|
+
WHERE {where_clause}
|
|
1003
|
+
ORDER BY seq_id ASC
|
|
1004
|
+
"""
|
|
1005
|
+
bounded = CURRENT_HISTORY_READ_BUDGET.get() is not None
|
|
1006
|
+
async with (connection.transaction(isolation="repeatable_read", readonly=True)
|
|
1007
|
+
if bounded else nullcontext()):
|
|
1008
|
+
body_bytes = None
|
|
1009
|
+
if bounded:
|
|
1010
|
+
candidate = (
|
|
1011
|
+
f"SELECT content_json,state_delta_json,metadata_json "
|
|
1012
|
+
f"FROM {KSADK_PG_EVENTS_TABLE} WHERE {where_clause} "
|
|
1013
|
+
"ORDER BY seq_id DESC "
|
|
1014
|
+
)
|
|
1015
|
+
if limit is not None:
|
|
1016
|
+
candidate += f"LIMIT ${limit_param} OFFSET ${offset_param}"
|
|
1017
|
+
elif offset is not None:
|
|
1018
|
+
candidate += f"OFFSET ${offset_param}"
|
|
1019
|
+
body_bytes = await self._precheck_history_body(connection, candidate, params)
|
|
1020
|
+
if bounded:
|
|
1021
|
+
rows = await connection.fetch_history_page(query, *params, estimated_bytes=body_bytes)
|
|
1022
|
+
else:
|
|
1023
|
+
fetch = connection.fetch_replay if limit is None else connection.fetch
|
|
1024
|
+
rows = await fetch(query, *params)
|
|
1025
|
+
return [self._event_from_row(row) for row in rows]
|
|
1026
|
+
|
|
1027
|
+
async def get_message_event_window(
|
|
1028
|
+
self, session_id: str, *, limit: int, from_start: bool = False,
|
|
1029
|
+
after_seq_id: int | None = None, before_seq_id: int | None = None,
|
|
1030
|
+
byte_limit: int = 64 * 1024,
|
|
1031
|
+
) -> list[SessionEvent]:
|
|
1032
|
+
"""Initial message projection window, bounded by rows AND JSON bytes.
|
|
1033
|
+
|
|
1034
|
+
This is deliberately separate from get_events/query_events: those APIs
|
|
1035
|
+
must retain their exact row-limit semantics. The caller completes the
|
|
1036
|
+
boundary invocation before returning any messages to the client.
|
|
1037
|
+
"""
|
|
1038
|
+
if not 1 <= limit <= 256:
|
|
1039
|
+
raise ValueError('Message projection window must be between 1 and 256 events')
|
|
1040
|
+
if not 1 <= byte_limit <= 512 * 1024:
|
|
1041
|
+
raise ValueError('Message projection window must be between 1 and 512 KiB')
|
|
1042
|
+
if from_start and type(self).query_events is not PostgresSessionService.query_events:
|
|
1043
|
+
return await self.query_events(SessionEventQuery(
|
|
1044
|
+
session_ids=[session_id], from_start=True, order_by_seq=True,
|
|
1045
|
+
limit=limit, after_seq_id=after_seq_id, before_seq_id=before_seq_id,
|
|
1046
|
+
))
|
|
1047
|
+
if not from_start and type(self).get_events is not PostgresSessionService.get_events:
|
|
1048
|
+
return await self.get_events(
|
|
1049
|
+
session_id, limit=limit, after_seq_id=after_seq_id, before_seq_id=before_seq_id,
|
|
1050
|
+
)
|
|
1051
|
+
await self._ensure_schema()
|
|
1052
|
+
conditions = ['namespace=$1', 'session_id=$2']
|
|
1053
|
+
_message_projection_filter(conditions)
|
|
1054
|
+
params: list[Any] = [self.namespace, session_id]
|
|
1055
|
+
for value, operator in ((after_seq_id, '>'), (before_seq_id, '<')):
|
|
1056
|
+
if value is not None:
|
|
1057
|
+
params.append(value)
|
|
1058
|
+
conditions.append(f'seq_id {operator} ${len(params)}')
|
|
1059
|
+
params.append(limit)
|
|
1060
|
+
direction = 'ASC' if from_start else 'DESC'
|
|
1061
|
+
fields = ('id,session_id,author,event_type,content_json,timestamp,'
|
|
1062
|
+
'state_delta_json,seq_id,invocation_id,metadata_json')
|
|
1063
|
+
budget = CURRENT_HISTORY_READ_BUDGET.get()
|
|
1064
|
+
limit_param = len(params)
|
|
1065
|
+
params.append(budget.remaining if budget is not None else 2**63 - 1)
|
|
1066
|
+
byte_param = len(params)
|
|
1067
|
+
# A single statement gives the byte check and returned rows the same
|
|
1068
|
+
# snapshot. PostgreSQL withholds all JSON bodies on overflow; only
|
|
1069
|
+
# bounded row metadata and the required byte count cross the socket.
|
|
1070
|
+
# This avoids BEGIN/preflight/fetch/COMMIT round trips on every page.
|
|
1071
|
+
returned_fields = ','.join(
|
|
1072
|
+
f'CASE WHEN required_bytes <= ${byte_param}::bigint THEN {field} ELSE NULL END AS {field}'
|
|
1073
|
+
if field in {'content_json', 'state_delta_json', 'metadata_json'} else field
|
|
1074
|
+
for field in fields.split(',')
|
|
1075
|
+
)
|
|
1076
|
+
# Include variable-length identity columns and a conservative allowance
|
|
1077
|
+
# for numeric values, DataRow framing and the returned guard columns.
|
|
1078
|
+
# Crossing a byte ceiling with one additional large tool event nearly
|
|
1079
|
+
# doubles a transfer and synchronizes slow responses under load. Only
|
|
1080
|
+
# the first event may exceed the window, so an indivisible event still
|
|
1081
|
+
# makes progress (subject to the unchanged total request byte budget).
|
|
1082
|
+
wire_overhead = ' + '.join(
|
|
1083
|
+
f'COALESCE(octet_length({field}::text),0)'
|
|
1084
|
+
for field in ('id', 'session_id', 'author', 'event_type', 'invocation_id')
|
|
1085
|
+
) + ' + 128'
|
|
1086
|
+
query = f'''
|
|
1087
|
+
WITH bounded AS (
|
|
1088
|
+
SELECT {fields},
|
|
1089
|
+
COALESCE(octet_length(content_json::text),0) +
|
|
1090
|
+
COALESCE(octet_length(state_delta_json::text),0) +
|
|
1091
|
+
COALESCE(octet_length(metadata_json::text),0) AS body_bytes,
|
|
1092
|
+
{wire_overhead} AS wire_overhead
|
|
1093
|
+
FROM {KSADK_PG_EVENTS_TABLE}
|
|
1094
|
+
WHERE {' AND '.join(conditions)}
|
|
1095
|
+
ORDER BY seq_id {direction} LIMIT ${limit_param}
|
|
1096
|
+
), measured AS (
|
|
1097
|
+
SELECT *, ROW_NUMBER() OVER (ORDER BY seq_id {direction}) AS position,
|
|
1098
|
+
SUM(body_bytes + wire_overhead) OVER (
|
|
1099
|
+
ORDER BY seq_id {direction} ROWS UNBOUNDED PRECEDING
|
|
1100
|
+
) AS cumulative_bytes FROM bounded
|
|
1101
|
+
), candidates AS (
|
|
1102
|
+
SELECT * FROM measured
|
|
1103
|
+
WHERE cumulative_bytes <= {byte_limit} OR position = 1
|
|
1104
|
+
), checked AS (
|
|
1105
|
+
SELECT *, SUM(body_bytes + 1024) OVER () AS required_bytes,
|
|
1106
|
+
((SELECT COUNT(*) FROM bounded) < {limit}
|
|
1107
|
+
AND COUNT(*) OVER () = (SELECT COUNT(*) FROM bounded)) AS source_exhausted
|
|
1108
|
+
FROM candidates
|
|
1109
|
+
)
|
|
1110
|
+
SELECT {returned_fields}, source_exhausted, required_bytes FROM checked
|
|
1111
|
+
ORDER BY seq_id ASC
|
|
1112
|
+
'''
|
|
1113
|
+
# Small individual windows still create a large burst when many
|
|
1114
|
+
# projections fetch them simultaneously. Only the bounded non-Kernel
|
|
1115
|
+
# projection scope shares this gate; metadata, writes, replay and
|
|
1116
|
+
# ordinary/Kernel reads retain their existing concurrency. Waiting is
|
|
1117
|
+
# inside the projection's original deadline and never retries a query.
|
|
1118
|
+
shared = self._history_read_lease.get()
|
|
1119
|
+
gate = (self._history_transfer_slots
|
|
1120
|
+
if shared is not None and shared[0] is asyncio.current_task()
|
|
1121
|
+
else nullcontext())
|
|
1122
|
+
async with gate:
|
|
1123
|
+
async with self._connection() as connection:
|
|
1124
|
+
rows = await connection.fetch(query, *params)
|
|
1125
|
+
if budget is not None and rows:
|
|
1126
|
+
budget.account(int(rows[0]['required_bytes']))
|
|
1127
|
+
return _HistoryEventWindow(
|
|
1128
|
+
[self._event_from_row(row) for row in rows],
|
|
1129
|
+
source_exhausted=bool(rows[0]['source_exhausted']) if rows else True,
|
|
1130
|
+
)
|
|
1131
|
+
|
|
1132
|
+
async def get_session_summary_events(self, session_id: str) -> list[SessionEvent]:
|
|
1133
|
+
"""Fetch prompt endpoints and the exact active/latest run summary.
|
|
1134
|
+
|
|
1135
|
+
PostgreSQL ranks lifecycle facts by invocation without sending their JSON
|
|
1136
|
+
bodies to Python. A terminal run cannot hide an older active run after
|
|
1137
|
+
more than one page of lifecycle events.
|
|
1138
|
+
"""
|
|
1139
|
+
queries = [
|
|
1140
|
+
SessionEventQuery(session_ids=[session_id], event_types=["user_message"],
|
|
1141
|
+
limit=1, from_start=True, order_by_seq=True),
|
|
1142
|
+
SessionEventQuery(session_ids=[session_id], event_types=["user_message"],
|
|
1143
|
+
limit=1, order_by_seq=True),
|
|
1144
|
+
]
|
|
1145
|
+
selected: dict[str, SessionEvent] = {}
|
|
1146
|
+
for query in queries:
|
|
1147
|
+
selected.update({event.id: event for event in await self.query_events(query)})
|
|
1148
|
+
run_id = "COALESCE(NULLIF(metadata_json->>'run_id',''), NULLIF(metadata_json->>'invocation_id',''), NULLIF(invocation_id,''), '')"
|
|
1149
|
+
status = (
|
|
1150
|
+
"COALESCE(NULLIF(metadata_json->>'status',''), "
|
|
1151
|
+
"NULLIF(metadata_json->>'run_status',''), NULLIF(content_json->>'status',''), "
|
|
1152
|
+
"NULLIF(content_json->'payload'->>'status',''), "
|
|
1153
|
+
"CASE event_type WHEN 'run.started' THEN 'in_progress' "
|
|
1154
|
+
"WHEN 'run.progress' THEN 'in_progress' "
|
|
1155
|
+
"WHEN 'run.interrupted' THEN 'interrupted' "
|
|
1156
|
+
"WHEN 'run.completed' THEN 'completed' "
|
|
1157
|
+
"WHEN 'run.failed' THEN 'failed' "
|
|
1158
|
+
"WHEN 'run.canceled' THEN 'cancelled' ELSE '' END)"
|
|
1159
|
+
)
|
|
1160
|
+
await self._ensure_schema()
|
|
1161
|
+
async with self._connection() as connection:
|
|
1162
|
+
row = await connection.fetchrow(
|
|
1163
|
+
f"""WITH facts AS (
|
|
1164
|
+
SELECT id, seq_id, timestamp, event_type, {run_id} AS run_id,
|
|
1165
|
+
{status} AS status,
|
|
1166
|
+
COALESCE(metadata_json->>'run_mode','unknown') AS run_mode,
|
|
1167
|
+
COALESCE(metadata_json->>'run_trigger','unknown') AS run_trigger
|
|
1168
|
+
FROM {KSADK_PG_EVENTS_TABLE}
|
|
1169
|
+
WHERE namespace=$1 AND session_id=$2 AND event_type=ANY($3::text[])
|
|
1170
|
+
), latest AS (
|
|
1171
|
+
SELECT DISTINCT ON (run_id) * FROM facts
|
|
1172
|
+
ORDER BY run_id, seq_id DESC
|
|
1173
|
+
), chosen AS (
|
|
1174
|
+
SELECT * FROM latest
|
|
1175
|
+
ORDER BY CASE WHEN status=ANY($4::text[]) THEN 0
|
|
1176
|
+
WHEN status<>ALL($5::text[]) THEN 1 ELSE 2 END,
|
|
1177
|
+
seq_id DESC LIMIT 1
|
|
1178
|
+
)
|
|
1179
|
+
SELECT chosen.*, classified.run_mode AS classified_mode,
|
|
1180
|
+
classified.run_trigger AS classified_trigger
|
|
1181
|
+
FROM chosen LEFT JOIN LATERAL (
|
|
1182
|
+
SELECT facts.run_mode, facts.run_trigger FROM facts
|
|
1183
|
+
WHERE facts.run_id=chosen.run_id AND
|
|
1184
|
+
(facts.run_mode<>'unknown' OR facts.run_trigger<>'unknown')
|
|
1185
|
+
ORDER BY facts.seq_id DESC LIMIT 1
|
|
1186
|
+
) classified ON true""",
|
|
1187
|
+
self.namespace, session_id,
|
|
1188
|
+
["run_status", "run.started", "run.progress", "run.interrupted",
|
|
1189
|
+
"run.completed", "run.failed", "run.canceled"],
|
|
1190
|
+
["in_progress", "running", "resuming", "starting"],
|
|
1191
|
+
["completed", "failed", "error", "cancelled", "canceled", "aborted",
|
|
1192
|
+
"interrupted", "resume_failed"],
|
|
1193
|
+
)
|
|
1194
|
+
if row is not None:
|
|
1195
|
+
selected[row["id"]] = SessionEvent(
|
|
1196
|
+
id=row["id"], session_id=session_id, event_type=row["event_type"],
|
|
1197
|
+
seq_id=int(row["seq_id"]), timestamp=float(row["timestamp"]),
|
|
1198
|
+
invocation_id=row["run_id"], content={"status": row["status"]},
|
|
1199
|
+
metadata={"run_id": row["run_id"], "status": row["status"],
|
|
1200
|
+
"run_mode": row["classified_mode"] or row["run_mode"],
|
|
1201
|
+
"run_trigger": row["classified_trigger"] or row["run_trigger"]},
|
|
1202
|
+
)
|
|
1203
|
+
return sorted(selected.values(), key=lambda event: event.seq_id)
|
|
1204
|
+
|
|
1205
|
+
async def get_max_seq_id(self, session_id: str) -> int:
|
|
1206
|
+
"""Find a history snapshot boundary without fetching event JSON."""
|
|
1207
|
+
await self._ensure_schema()
|
|
1208
|
+
async with self._connection() as connection:
|
|
1209
|
+
return int(await connection.fetchval(
|
|
1210
|
+
f"SELECT COALESCE(MAX(seq_id),0) FROM {KSADK_PG_EVENTS_TABLE} "
|
|
1211
|
+
"WHERE namespace=$1 AND session_id=$2",
|
|
1212
|
+
self.namespace, session_id,
|
|
1213
|
+
) or 0)
|
|
1214
|
+
|
|
1215
|
+
async def has_events(
|
|
1216
|
+
self, session_id: str, *, after_seq_id: int | None = None,
|
|
1217
|
+
before_seq_id: int | None = None,
|
|
1218
|
+
) -> bool:
|
|
1219
|
+
"""Probe a page boundary without transferring a potentially huge body."""
|
|
1220
|
+
await self._ensure_schema()
|
|
1221
|
+
clauses = ["namespace=$1", "session_id=$2"]
|
|
1222
|
+
_message_projection_filter(clauses)
|
|
1223
|
+
params: list[Any] = [self.namespace, session_id]
|
|
1224
|
+
if after_seq_id is not None:
|
|
1225
|
+
params.append(after_seq_id)
|
|
1226
|
+
clauses.append(f"seq_id>${len(params)}")
|
|
1227
|
+
if before_seq_id is not None:
|
|
1228
|
+
params.append(before_seq_id)
|
|
1229
|
+
clauses.append(f"seq_id<${len(params)}")
|
|
1230
|
+
async with self._connection() as connection:
|
|
1231
|
+
return bool(await connection.fetchval(
|
|
1232
|
+
f"SELECT EXISTS(SELECT 1 FROM {KSADK_PG_EVENTS_TABLE} "
|
|
1233
|
+
f"WHERE {' AND '.join(clauses)})", *params,
|
|
1234
|
+
))
|
|
1235
|
+
|
|
1236
|
+
async def count_events(
|
|
1237
|
+
self,
|
|
1238
|
+
session_id: str,
|
|
1239
|
+
after_seq_id: Optional[int] = None,
|
|
1240
|
+
before_seq_id: Optional[int] = None,
|
|
1241
|
+
) -> int:
|
|
1242
|
+
await self._ensure_schema()
|
|
1243
|
+
conditions = ["namespace = $1", "session_id = $2"]
|
|
1244
|
+
_message_projection_filter(conditions)
|
|
1245
|
+
params: list[Any] = [self.namespace, session_id]
|
|
1246
|
+
if after_seq_id is not None:
|
|
1247
|
+
params.append(after_seq_id)
|
|
1248
|
+
conditions.append(f"seq_id > ${len(params)}")
|
|
1249
|
+
if before_seq_id is not None:
|
|
1250
|
+
params.append(before_seq_id)
|
|
1251
|
+
conditions.append(f"seq_id < ${len(params)}")
|
|
1252
|
+
where_clause = " AND ".join(conditions)
|
|
1253
|
+
async with self._connection() as connection:
|
|
1254
|
+
query = f"""
|
|
1255
|
+
SELECT COUNT(*) AS total
|
|
1256
|
+
FROM {KSADK_PG_EVENTS_TABLE}
|
|
1257
|
+
WHERE {where_clause}
|
|
1258
|
+
"""
|
|
1259
|
+
return int(await connection.fetchval(query, *params) or 0)
|
|
1260
|
+
|
|
1261
|
+
async def get_sessions_by_ids(self, session_ids: list[str]) -> list[Session]:
|
|
1262
|
+
if not session_ids:
|
|
1263
|
+
return []
|
|
1264
|
+
await self._ensure_schema()
|
|
1265
|
+
async with self._connection() as connection:
|
|
1266
|
+
rows = await connection.fetch(
|
|
1267
|
+
f"SELECT id,agent_id,user_id,title,title_source,summary,first_prompt,"
|
|
1268
|
+
f"last_prompt,state_json,created_at,updated_at,version "
|
|
1269
|
+
f"FROM {KSADK_PG_SESSIONS_TABLE} WHERE namespace=$1 "
|
|
1270
|
+
"AND id=ANY($2::text[])",
|
|
1271
|
+
self.namespace,
|
|
1272
|
+
session_ids,
|
|
1273
|
+
)
|
|
1274
|
+
by_id = {row["id"]: self._session_from_row(row, events=[]) for row in rows}
|
|
1275
|
+
return [by_id[item] for item in session_ids if item in by_id]
|
|
1276
|
+
|
|
1277
|
+
async def get_session_ids_by_ids(
|
|
1278
|
+
self, session_ids: list[str], agent_id: str | None = None,
|
|
1279
|
+
) -> list[str]:
|
|
1280
|
+
if not session_ids:
|
|
1281
|
+
return []
|
|
1282
|
+
await self._ensure_schema()
|
|
1283
|
+
async with self._connection() as connection:
|
|
1284
|
+
rows = await connection.fetch(
|
|
1285
|
+
f"SELECT id FROM {KSADK_PG_SESSIONS_TABLE} WHERE namespace=$1 "
|
|
1286
|
+
"AND id=ANY($2::text[])"
|
|
1287
|
+
+ (" AND agent_id=$3" if agent_id is not None else ""),
|
|
1288
|
+
self.namespace, session_ids, *([agent_id] if agent_id is not None else []),
|
|
1289
|
+
)
|
|
1290
|
+
found = {row["id"] for row in rows}
|
|
1291
|
+
return [sid for sid in session_ids if sid in found]
|
|
1292
|
+
|
|
1293
|
+
async def list_session_ids(
|
|
1294
|
+
self, agent_id: str | None = None, user_id: str | None = None,
|
|
1295
|
+
) -> list[str]:
|
|
1296
|
+
await self._ensure_schema()
|
|
1297
|
+
clauses = ["namespace=$1"]
|
|
1298
|
+
params: list[Any] = [self.namespace]
|
|
1299
|
+
for column, value in (("agent_id", agent_id), ("user_id", user_id)):
|
|
1300
|
+
if value is not None:
|
|
1301
|
+
params.append(value)
|
|
1302
|
+
clauses.append(f"{column}=${len(params)}")
|
|
1303
|
+
async with self._connection() as connection:
|
|
1304
|
+
rows = await connection.fetch(
|
|
1305
|
+
f"SELECT id FROM {KSADK_PG_SESSIONS_TABLE} WHERE {' AND '.join(clauses)}",
|
|
1306
|
+
*params,
|
|
1307
|
+
)
|
|
1308
|
+
return [row["id"] for row in rows]
|
|
1309
|
+
|
|
1310
|
+
async def list_session_metadata(
|
|
1311
|
+
self, agent_id: Optional[str] = None, user_id: Optional[str] = None
|
|
1312
|
+
) -> list[Session]:
|
|
1313
|
+
await self._ensure_schema()
|
|
1314
|
+
clauses = ["namespace=$1"]
|
|
1315
|
+
params: list[Any] = [self.namespace]
|
|
1316
|
+
if agent_id is not None:
|
|
1317
|
+
params.append(agent_id)
|
|
1318
|
+
clauses.append(f"agent_id=${len(params)}")
|
|
1319
|
+
if user_id is not None:
|
|
1320
|
+
params.append(user_id)
|
|
1321
|
+
clauses.append(f"user_id=${len(params)}")
|
|
1322
|
+
async with self._connection() as connection:
|
|
1323
|
+
rows = await connection.fetch(
|
|
1324
|
+
f"SELECT id,agent_id,user_id,title,title_source,summary,first_prompt,"
|
|
1325
|
+
f"last_prompt,state_json,created_at,updated_at,version "
|
|
1326
|
+
f"FROM {KSADK_PG_SESSIONS_TABLE} WHERE {' AND '.join(clauses)} "
|
|
1327
|
+
"ORDER BY updated_at DESC,created_at DESC,id DESC",
|
|
1328
|
+
*params,
|
|
1329
|
+
)
|
|
1330
|
+
return [self._session_from_row(row, events=[]) for row in rows]
|
|
1331
|
+
|
|
1332
|
+
def _batch_event_where(self, query: SessionEventQuery) -> tuple[list[str], list[Any]]:
|
|
1333
|
+
clauses = ["event_row.namespace=$1"]
|
|
1334
|
+
_message_projection_filter(clauses, "event_row.")
|
|
1335
|
+
params: list[Any] = [self.namespace]
|
|
1336
|
+
if query.session_ids is not None:
|
|
1337
|
+
if not query.session_ids:
|
|
1338
|
+
return ["FALSE"], []
|
|
1339
|
+
params.append(query.session_ids)
|
|
1340
|
+
clauses.append(f"event_row.session_id=ANY(${len(params)}::text[])")
|
|
1341
|
+
for value, clause in (
|
|
1342
|
+
(query.agent_id, "session_row.agent_id"),
|
|
1343
|
+
(query.after_seq_id, "event_row.seq_id >"),
|
|
1344
|
+
(query.before_seq_id, "event_row.seq_id <"),
|
|
1345
|
+
(query.invocation_id, "event_row.invocation_id"),
|
|
1346
|
+
):
|
|
1347
|
+
if value is not None:
|
|
1348
|
+
params.append(value)
|
|
1349
|
+
operator = "" if clause.endswith((">", "<")) else "="
|
|
1350
|
+
clauses.append(f"{clause}{operator}${len(params)}")
|
|
1351
|
+
if query.event_types:
|
|
1352
|
+
params.append(query.event_types)
|
|
1353
|
+
clauses.append(f"event_row.event_type=ANY(${len(params)}::text[])")
|
|
1354
|
+
if query.run_id is not None:
|
|
1355
|
+
params.append(query.run_id)
|
|
1356
|
+
clauses.append(
|
|
1357
|
+
"(event_row.metadata_json->>'run_id'="
|
|
1358
|
+
f"${len(params)}"
|
|
1359
|
+
f" OR event_row.metadata_json->'tool_receipt'->>'run_id'=${len(params)}"
|
|
1360
|
+
" OR (event_row.event_type='continuation.created'"
|
|
1361
|
+
f" AND event_row.content_json->'runtime_event'->>'run_id'=${len(params)}))"
|
|
1362
|
+
)
|
|
1363
|
+
if query.checkpoint_id is not None:
|
|
1364
|
+
params.append(query.checkpoint_id)
|
|
1365
|
+
clauses.append(
|
|
1366
|
+
"(event_row.metadata_json->>'checkpoint_id'="
|
|
1367
|
+
f"${len(params)}"
|
|
1368
|
+
f" OR event_row.metadata_json->'tool_receipt'->>'checkpoint_id'=${len(params)}"
|
|
1369
|
+
" OR (event_row.event_type='continuation.created'"
|
|
1370
|
+
f" AND event_row.content_json->'runtime_event'->>'continuation_id'=${len(params)}))"
|
|
1371
|
+
)
|
|
1372
|
+
if query.checkpoint_ids:
|
|
1373
|
+
params.append(query.checkpoint_ids)
|
|
1374
|
+
clauses.append(
|
|
1375
|
+
"(event_row.metadata_json->>'checkpoint_id'=ANY("
|
|
1376
|
+
f"${len(params)}::text[])"
|
|
1377
|
+
" OR (event_row.event_type='continuation.created'"
|
|
1378
|
+
" AND event_row.content_json->'runtime_event'->>'continuation_id'=ANY("
|
|
1379
|
+
f"${len(params)}::text[])))"
|
|
1380
|
+
)
|
|
1381
|
+
if query.receipt_only:
|
|
1382
|
+
clauses.append(
|
|
1383
|
+
"event_row.event_type='tool_result' AND "
|
|
1384
|
+
"jsonb_typeof(event_row.metadata_json->'tool_receipt')='object' AND "
|
|
1385
|
+
"btrim(coalesce(nullif(event_row.metadata_json->'tool_receipt'->>'tool_name', ''), "
|
|
1386
|
+
"event_row.metadata_json->>'tool_name', ''))<>''"
|
|
1387
|
+
)
|
|
1388
|
+
return clauses, params
|
|
1389
|
+
|
|
1390
|
+
async def query_events(self, query: SessionEventQuery) -> list[SessionEvent]:
|
|
1391
|
+
return await self._query_events(query)
|
|
1392
|
+
|
|
1393
|
+
async def get_raw_event_page(
|
|
1394
|
+
self, query: SessionEventQuery, *, byte_limit: int = 512 * 1024,
|
|
1395
|
+
) -> list[SessionEvent]:
|
|
1396
|
+
"""HTTP-only byte paging; ordinary query/replay row contracts stay exact."""
|
|
1397
|
+
if type(self).query_events is not PostgresSessionService.query_events:
|
|
1398
|
+
return await self.query_events(query)
|
|
1399
|
+
return await self._query_events(query, byte_limit=byte_limit)
|
|
1400
|
+
|
|
1401
|
+
async def _query_events(
|
|
1402
|
+
self, query: SessionEventQuery, *, byte_limit: int | None = None,
|
|
1403
|
+
) -> list[SessionEvent]:
|
|
1404
|
+
await self._ensure_schema()
|
|
1405
|
+
clauses, params = self._batch_event_where(query)
|
|
1406
|
+
direction = "ASC" if query.from_start else "DESC"
|
|
1407
|
+
order = (
|
|
1408
|
+
f"event_row.session_id {direction},event_row.seq_id {direction},"
|
|
1409
|
+
f"event_row.id {direction}"
|
|
1410
|
+
if query.order_by_seq
|
|
1411
|
+
else f"event_row.timestamp {direction},event_row.session_id {direction},"
|
|
1412
|
+
f"event_row.seq_id {direction},event_row.id {direction}"
|
|
1413
|
+
)
|
|
1414
|
+
params.extend([query.limit, query.offset])
|
|
1415
|
+
statement = (
|
|
1416
|
+
f"SELECT event_row.id,event_row.session_id,event_row.author,event_row.event_type,"
|
|
1417
|
+
f"event_row.content_json,event_row.timestamp,event_row.state_delta_json,"
|
|
1418
|
+
f"event_row.seq_id,event_row.invocation_id,event_row.metadata_json "
|
|
1419
|
+
f"FROM {KSADK_PG_EVENTS_TABLE} event_row "
|
|
1420
|
+
f"JOIN {KSADK_PG_SESSIONS_TABLE} session_row "
|
|
1421
|
+
"ON session_row.namespace=event_row.namespace "
|
|
1422
|
+
"AND session_row.id=event_row.session_id "
|
|
1423
|
+
f"WHERE {' AND '.join(clauses)} ORDER BY {order} "
|
|
1424
|
+
f"LIMIT ${len(params)-1} OFFSET ${len(params)}"
|
|
1425
|
+
)
|
|
1426
|
+
if byte_limit is not None:
|
|
1427
|
+
if byte_limit <= 0:
|
|
1428
|
+
raise ValueError("Raw event page byte limit must be positive")
|
|
1429
|
+
page_order = order.replace("event_row.", "")
|
|
1430
|
+
params.append(byte_limit)
|
|
1431
|
+
statement = (
|
|
1432
|
+
# Plain CTEs also support PostgreSQL 9.6, still used by Kernel
|
|
1433
|
+
# deployments. LIMIT plus the window frame preserves the page
|
|
1434
|
+
# boundary on newer servers that may inline this CTE.
|
|
1435
|
+
f"WITH candidates AS ({statement}), sized AS ("
|
|
1436
|
+
f"SELECT *,row_number() OVER (ORDER BY {page_order}) AS page_rank,"
|
|
1437
|
+
"SUM(COALESCE(octet_length(content_json::text),0)+"
|
|
1438
|
+
"COALESCE(octet_length(state_delta_json::text),0)+"
|
|
1439
|
+
"COALESCE(octet_length(metadata_json::text),0)+1024) "
|
|
1440
|
+
f"OVER (ORDER BY {page_order} ROWS UNBOUNDED PRECEDING) AS page_bytes "
|
|
1441
|
+
"FROM candidates) SELECT id,session_id,author,event_type,content_json,"
|
|
1442
|
+
"timestamp,state_delta_json,seq_id,invocation_id,metadata_json FROM sized "
|
|
1443
|
+
f"WHERE page_rank=1 OR page_bytes<=${len(params)} ORDER BY {page_order}"
|
|
1444
|
+
)
|
|
1445
|
+
async with self._connection() as connection:
|
|
1446
|
+
bounded = CURRENT_HISTORY_READ_BUDGET.get() is not None
|
|
1447
|
+
async with (connection.transaction(isolation="repeatable_read", readonly=True)
|
|
1448
|
+
if bounded else nullcontext()):
|
|
1449
|
+
body_bytes = await self._precheck_history_body(
|
|
1450
|
+
connection,
|
|
1451
|
+
statement,
|
|
1452
|
+
params,
|
|
1453
|
+
)
|
|
1454
|
+
fetch = connection.fetch_history_page if bounded else connection.fetch
|
|
1455
|
+
rows = await fetch(
|
|
1456
|
+
statement,
|
|
1457
|
+
*params,
|
|
1458
|
+
**({'estimated_bytes': body_bytes} if bounded else {}),
|
|
1459
|
+
)
|
|
1460
|
+
events = [self._event_from_row(row) for row in rows]
|
|
1461
|
+
if not query.from_start:
|
|
1462
|
+
events.reverse()
|
|
1463
|
+
return events
|
|
1464
|
+
|
|
1465
|
+
async def count_event_query(self, query: SessionEventQuery) -> int:
|
|
1466
|
+
await self._ensure_schema()
|
|
1467
|
+
clauses, params = self._batch_event_where(query)
|
|
1468
|
+
async with self._connection() as connection:
|
|
1469
|
+
return int(
|
|
1470
|
+
await connection.fetchval(
|
|
1471
|
+
f"SELECT COUNT(*) FROM {KSADK_PG_EVENTS_TABLE} event_row "
|
|
1472
|
+
f"JOIN {KSADK_PG_SESSIONS_TABLE} session_row "
|
|
1473
|
+
"ON session_row.namespace=event_row.namespace "
|
|
1474
|
+
"AND session_row.id=event_row.session_id "
|
|
1475
|
+
f"WHERE {' AND '.join(clauses)}",
|
|
1476
|
+
*params,
|
|
1477
|
+
)
|
|
1478
|
+
or 0
|
|
1479
|
+
)
|
|
1480
|
+
|
|
1481
|
+
async def scan_checkpoint_events(
|
|
1482
|
+
self, query: CheckpointEventQuery
|
|
1483
|
+
) -> list[SessionEvent]:
|
|
1484
|
+
if query.limit < 1 or query.limit > 50:
|
|
1485
|
+
raise ValueError("checkpoint scan limit must be between 1 and 50")
|
|
1486
|
+
return await self._scan_checkpoint_events_with_connection(None, query)
|
|
1487
|
+
|
|
1488
|
+
async def iter_resume_related_event_pages(
|
|
1489
|
+
self, session_id: str, *, page_size: int = 256,
|
|
1490
|
+
expected_session: Session | None = None,
|
|
1491
|
+
) -> AsyncIterator[list[SessionEvent]]:
|
|
1492
|
+
"""Scan only resume facts by sequence in one read-only snapshot."""
|
|
1493
|
+
await self._ensure_schema()
|
|
1494
|
+
kinds = ["run_checkpoint", "run_resume", "runtime_resume", "continuation.created", "continuation.resumed"]
|
|
1495
|
+
async with self._connection() as connection:
|
|
1496
|
+
async with connection.transaction(isolation="repeatable_read", readonly=True):
|
|
1497
|
+
if expected_session is not None:
|
|
1498
|
+
from ksadk.sessions.errors import HistoryReloadRequired
|
|
1499
|
+
|
|
1500
|
+
owner = await connection.fetchrow(
|
|
1501
|
+
f"SELECT agent_id,user_id,created_at FROM {KSADK_PG_SESSIONS_TABLE} "
|
|
1502
|
+
"WHERE namespace=$1 AND id=$2",
|
|
1503
|
+
self.namespace, session_id,
|
|
1504
|
+
)
|
|
1505
|
+
if (owner is None or owner["agent_id"] != expected_session.agent_id
|
|
1506
|
+
or owner["user_id"] != expected_session.user_id
|
|
1507
|
+
or float(owner["created_at"]) != expected_session.created_at):
|
|
1508
|
+
raise HistoryReloadRequired("Checkpoint session changed during lookup")
|
|
1509
|
+
upper = int(await connection.fetchval(
|
|
1510
|
+
f"SELECT COALESCE(MAX(seq_id),0) FROM {KSADK_PG_EVENTS_TABLE} "
|
|
1511
|
+
"WHERE namespace=$1 AND session_id=$2",
|
|
1512
|
+
self.namespace, session_id,
|
|
1513
|
+
) or 0)
|
|
1514
|
+
count = int(await connection.fetchval(
|
|
1515
|
+
f"SELECT COUNT(*) FROM {KSADK_PG_EVENTS_TABLE} "
|
|
1516
|
+
"WHERE namespace=$1 AND session_id=$2 AND event_type=ANY($3::text[]) "
|
|
1517
|
+
"AND seq_id<=$4",
|
|
1518
|
+
self.namespace, session_id, kinds, upper,
|
|
1519
|
+
) or 0)
|
|
1520
|
+
if count > 8192:
|
|
1521
|
+
raise HistoryProjectionBudgetExceeded(
|
|
1522
|
+
"Checkpoint lookup exceeds 8192 related events"
|
|
1523
|
+
)
|
|
1524
|
+
cursor = 0
|
|
1525
|
+
used = 0
|
|
1526
|
+
while True:
|
|
1527
|
+
candidates = (
|
|
1528
|
+
f"FROM {KSADK_PG_EVENTS_TABLE} WHERE namespace=$1 AND session_id=$2 "
|
|
1529
|
+
"AND event_type=ANY($3::text[]) AND seq_id>$4 AND seq_id<=$5 "
|
|
1530
|
+
"ORDER BY seq_id,id LIMIT $6"
|
|
1531
|
+
)
|
|
1532
|
+
args = (self.namespace, session_id, kinds, cursor, upper, page_size)
|
|
1533
|
+
size = int(await connection.fetchval(
|
|
1534
|
+
"SELECT COALESCE(SUM(octet_length(content_json::text)+"
|
|
1535
|
+
"octet_length(state_delta_json::text)+"
|
|
1536
|
+
"octet_length(metadata_json::text)+"
|
|
1537
|
+
"octet_length(to_jsonb(id)::text)+"
|
|
1538
|
+
"octet_length(to_jsonb(session_id)::text)+"
|
|
1539
|
+
"octet_length(to_jsonb(author)::text)+"
|
|
1540
|
+
"octet_length(to_jsonb(event_type)::text)+"
|
|
1541
|
+
"COALESCE(octet_length(to_jsonb(invocation_id)::text),0)+256),0) "
|
|
1542
|
+
"FROM (SELECT id,session_id,author,event_type,invocation_id,"
|
|
1543
|
+
"content_json,state_delta_json,metadata_json "
|
|
1544
|
+
+ candidates + ") AS resume_candidates",
|
|
1545
|
+
*args,
|
|
1546
|
+
) or 0)
|
|
1547
|
+
if used + size > 16 * 1024 * 1024:
|
|
1548
|
+
raise HistoryProjectionBudgetExceeded(
|
|
1549
|
+
"Checkpoint lookup exceeds 16 MiB of related events"
|
|
1550
|
+
)
|
|
1551
|
+
rows = await connection.fetch(
|
|
1552
|
+
"SELECT id,session_id,author,event_type,content_json,timestamp,"
|
|
1553
|
+
"state_delta_json,seq_id,invocation_id,metadata_json "
|
|
1554
|
+
+ candidates, *args,
|
|
1555
|
+
)
|
|
1556
|
+
if not rows:
|
|
1557
|
+
break
|
|
1558
|
+
yield [self._event_from_row(row) for row in rows]
|
|
1559
|
+
used += size
|
|
1560
|
+
cursor = int(rows[-1]["seq_id"])
|
|
1561
|
+
if len(rows) < page_size:
|
|
1562
|
+
break
|
|
1563
|
+
|
|
1564
|
+
async def _scan_checkpoint_events_with_connection(
|
|
1565
|
+
self,
|
|
1566
|
+
connection: Any | None,
|
|
1567
|
+
query: CheckpointEventQuery,
|
|
1568
|
+
cursor: tuple[float, str, int, str] | None = None,
|
|
1569
|
+
) -> list[SessionEvent]:
|
|
1570
|
+
event_query = SessionEventQuery(
|
|
1571
|
+
session_ids=query.session_ids,
|
|
1572
|
+
agent_id=query.agent_id,
|
|
1573
|
+
event_types=["run_checkpoint", "continuation.created"],
|
|
1574
|
+
checkpoint_ids=query.checkpoint_ids,
|
|
1575
|
+
run_id=query.run_id,
|
|
1576
|
+
offset=query.offset,
|
|
1577
|
+
limit=query.limit,
|
|
1578
|
+
from_start=True,
|
|
1579
|
+
)
|
|
1580
|
+
if query.framework is None and connection is None:
|
|
1581
|
+
return await self.query_events(event_query)
|
|
1582
|
+
if connection is None:
|
|
1583
|
+
async with self._connection() as owned:
|
|
1584
|
+
bounded = CURRENT_HISTORY_READ_BUDGET.get() is not None
|
|
1585
|
+
async with (owned.transaction(isolation="repeatable_read", readonly=True)
|
|
1586
|
+
if bounded else nullcontext()):
|
|
1587
|
+
return await self._scan_checkpoint_events_with_connection(
|
|
1588
|
+
owned, query, cursor,
|
|
1589
|
+
)
|
|
1590
|
+
await self._ensure_schema()
|
|
1591
|
+
clauses, params = self._batch_event_where(event_query)
|
|
1592
|
+
if query.framework is not None:
|
|
1593
|
+
params.append(query.framework.lower())
|
|
1594
|
+
clauses.append(
|
|
1595
|
+
"(lower(event_row.metadata_json->>'framework')="
|
|
1596
|
+
f"${len(params)}"
|
|
1597
|
+
" OR (event_row.event_type='continuation.created'"
|
|
1598
|
+
" AND lower(event_row.content_json->'runtime_event'->'source'->>'framework')="
|
|
1599
|
+
f"${len(params)}))"
|
|
1600
|
+
)
|
|
1601
|
+
if cursor is not None:
|
|
1602
|
+
placeholders = []
|
|
1603
|
+
for value in cursor:
|
|
1604
|
+
params.append(value)
|
|
1605
|
+
placeholders.append(f"${len(params)}")
|
|
1606
|
+
clauses.append(
|
|
1607
|
+
"(event_row.timestamp,event_row.session_id,event_row.seq_id,event_row.id) > "
|
|
1608
|
+
f"({','.join(placeholders)})"
|
|
1609
|
+
)
|
|
1610
|
+
params.extend([query.limit, query.offset])
|
|
1611
|
+
candidates = (
|
|
1612
|
+
f"FROM {KSADK_PG_EVENTS_TABLE} event_row "
|
|
1613
|
+
f"JOIN {KSADK_PG_SESSIONS_TABLE} session_row "
|
|
1614
|
+
"ON session_row.namespace=event_row.namespace "
|
|
1615
|
+
"AND session_row.id=event_row.session_id "
|
|
1616
|
+
f"WHERE {' AND '.join(clauses)} ORDER BY event_row.timestamp,event_row.session_id,"
|
|
1617
|
+
f"event_row.seq_id,event_row.id LIMIT ${len(params)-1} OFFSET ${len(params)}"
|
|
1618
|
+
)
|
|
1619
|
+
await self._precheck_history_body(
|
|
1620
|
+
connection,
|
|
1621
|
+
"SELECT event_row.content_json,event_row.state_delta_json,"
|
|
1622
|
+
"event_row.metadata_json " + candidates,
|
|
1623
|
+
params,
|
|
1624
|
+
)
|
|
1625
|
+
rows = await connection.fetch(
|
|
1626
|
+
"SELECT event_row.id,event_row.session_id,event_row.author,event_row.event_type,"
|
|
1627
|
+
"event_row.content_json,event_row.timestamp,event_row.state_delta_json,"
|
|
1628
|
+
"event_row.seq_id,event_row.invocation_id,event_row.metadata_json "
|
|
1629
|
+
+ candidates,
|
|
1630
|
+
*params,
|
|
1631
|
+
)
|
|
1632
|
+
return [self._event_from_row(row) for row in rows]
|
|
1633
|
+
|
|
1634
|
+
async def iter_checkpoint_event_chunks(
|
|
1635
|
+
self, query: CheckpointEventQuery
|
|
1636
|
+
) -> AsyncIterator[list[SessionEvent]]:
|
|
1637
|
+
if query.limit < 1 or query.limit > 50:
|
|
1638
|
+
raise ValueError("checkpoint scan limit must be between 1 and 50")
|
|
1639
|
+
await self._ensure_schema()
|
|
1640
|
+
async with self._connection() as connection:
|
|
1641
|
+
async with connection.transaction(isolation="repeatable_read", readonly=True):
|
|
1642
|
+
token = self._checkpoint_snapshot_connection.set(connection)
|
|
1643
|
+
try:
|
|
1644
|
+
cursor: tuple[float, str, int, str] | None = None
|
|
1645
|
+
first_page = True
|
|
1646
|
+
while True:
|
|
1647
|
+
batch = await self._scan_checkpoint_events_with_connection(
|
|
1648
|
+
connection,
|
|
1649
|
+
CheckpointEventQuery(
|
|
1650
|
+
**{
|
|
1651
|
+
**query.__dict__,
|
|
1652
|
+
"offset": query.offset if first_page else 0,
|
|
1653
|
+
}
|
|
1654
|
+
),
|
|
1655
|
+
cursor,
|
|
1656
|
+
)
|
|
1657
|
+
if not batch:
|
|
1658
|
+
break
|
|
1659
|
+
yield batch
|
|
1660
|
+
if len(batch) < query.limit:
|
|
1661
|
+
break
|
|
1662
|
+
last = batch[-1]
|
|
1663
|
+
cursor = (
|
|
1664
|
+
last.timestamp,
|
|
1665
|
+
last.session_id,
|
|
1666
|
+
last.seq_id,
|
|
1667
|
+
last.id,
|
|
1668
|
+
)
|
|
1669
|
+
first_page = False
|
|
1670
|
+
finally:
|
|
1671
|
+
self._checkpoint_snapshot_connection.reset(token)
|
|
1672
|
+
|
|
1673
|
+
async def get_checkpoint_lookup_stats(
|
|
1674
|
+
self, session_id: str, run_id: str, checkpoint_id: str
|
|
1675
|
+
) -> dict[str, object]:
|
|
1676
|
+
candidate = None
|
|
1677
|
+
max_seq_id = 0
|
|
1678
|
+
audit = CheckpointResumeAudit()
|
|
1679
|
+
async with asyncio.timeout(self.db_budget.write_operation_seconds):
|
|
1680
|
+
async with aclosing(self.iter_resume_related_event_pages(session_id)) as pages:
|
|
1681
|
+
async for page in pages:
|
|
1682
|
+
for event in page:
|
|
1683
|
+
creation = checkpoint_creation_identity(event)
|
|
1684
|
+
if event.event_type == "run_checkpoint":
|
|
1685
|
+
metadata = event.metadata or {}
|
|
1686
|
+
if str(metadata.get("run_id") or "") != run_id:
|
|
1687
|
+
continue
|
|
1688
|
+
max_seq_id = max(max_seq_id, event.seq_id)
|
|
1689
|
+
if str(metadata.get("checkpoint_id") or "") == checkpoint_id:
|
|
1690
|
+
candidate = event
|
|
1691
|
+
elif creation is not None:
|
|
1692
|
+
if creation == (run_id, checkpoint_id):
|
|
1693
|
+
max_seq_id = max(max_seq_id, event.seq_id)
|
|
1694
|
+
candidate = event
|
|
1695
|
+
else:
|
|
1696
|
+
identity = checkpoint_resume_identity(event)
|
|
1697
|
+
if identity is not None and identity[:2] == (run_id, checkpoint_id):
|
|
1698
|
+
audit.record(event, identity)
|
|
1699
|
+
return {"candidate": candidate, "max_seq_id": max_seq_id,
|
|
1700
|
+
"resume_count": audit["resume_count"],
|
|
1701
|
+
"last_resumed_at": audit["last_resumed_at"]}
|
|
1702
|
+
|
|
1703
|
+
async def get_checkpoint_stats(
|
|
1704
|
+
self, keys: list[tuple[str, str, str]]
|
|
1705
|
+
) -> dict[str, object]:
|
|
1706
|
+
from ksadk.sessions._postgres_checkpoint_stats import get_checkpoint_stats
|
|
1707
|
+
|
|
1708
|
+
if len(keys) > 50:
|
|
1709
|
+
raise ValueError("checkpoint stats batch cannot exceed 50 keys")
|
|
1710
|
+
if not keys:
|
|
1711
|
+
return {"audits": {}, "latest_seq_ids": {}}
|
|
1712
|
+
await self._ensure_schema()
|
|
1713
|
+
active = self._checkpoint_snapshot_connection.get()
|
|
1714
|
+
async with asyncio.timeout(self.db_budget.write_operation_seconds):
|
|
1715
|
+
async with (self._connection() if active is None else nullcontext(active)) as connection:
|
|
1716
|
+
async with (connection.transaction(isolation="repeatable_read", readonly=True)
|
|
1717
|
+
if active is None else nullcontext()):
|
|
1718
|
+
# The master aggregation validates every known carrier before
|
|
1719
|
+
# filtering identity. Bound its duplicated per-key JSON input
|
|
1720
|
+
# in the same snapshot, preserving fail-loud audit semantics.
|
|
1721
|
+
sessions = [key[0] for key in dict.fromkeys(keys)]
|
|
1722
|
+
sizes = await connection.fetchrow(
|
|
1723
|
+
f"SELECT COUNT(*) AS event_count, COALESCE(SUM("
|
|
1724
|
+
"octet_length(event_row.content_json::text)+"
|
|
1725
|
+
"octet_length(event_row.metadata_json::text)+1024),0) AS body_bytes "
|
|
1726
|
+
f"FROM {KSADK_PG_EVENTS_TABLE} event_row "
|
|
1727
|
+
"JOIN unnest($2::text[]) requested(session_id) "
|
|
1728
|
+
"ON event_row.session_id=requested.session_id "
|
|
1729
|
+
"WHERE event_row.namespace=$1 AND event_row.event_type IN "
|
|
1730
|
+
"('run_resume','runtime_resume','continuation.resumed','continuation.created')",
|
|
1731
|
+
self.namespace, sessions,
|
|
1732
|
+
)
|
|
1733
|
+
size = int(sizes["body_bytes"])
|
|
1734
|
+
if int(sizes["event_count"]) > 8192 or size > 16 * 1024 * 1024:
|
|
1735
|
+
raise HistoryProjectionBudgetExceeded("Checkpoint audit exceeds related-event budget")
|
|
1736
|
+
budget = CURRENT_HISTORY_READ_BUDGET.get()
|
|
1737
|
+
if budget is not None:
|
|
1738
|
+
budget.account(size)
|
|
1739
|
+
token = self._checkpoint_snapshot_connection.set(connection)
|
|
1740
|
+
try:
|
|
1741
|
+
return await get_checkpoint_stats(self, keys)
|
|
1742
|
+
finally:
|
|
1743
|
+
self._checkpoint_snapshot_connection.reset(token)
|
|
1744
|
+
|
|
884
1745
|
@_write_deadline
|
|
885
1746
|
async def claim_tool_receipt(self, session_id: str, **kwargs):
|
|
886
1747
|
return await super().claim_tool_receipt(session_id, **kwargs)
|
|
@@ -889,6 +1750,85 @@ class PostgresSessionService(_PostgresCheckpointReadMixin, _PostgresHistoryReadM
|
|
|
889
1750
|
async def settle_tool_receipt(self, session_id: str, **kwargs):
|
|
890
1751
|
return await super().settle_tool_receipt(session_id, **kwargs)
|
|
891
1752
|
|
|
1753
|
+
def _agent_events_query_parts(
|
|
1754
|
+
self,
|
|
1755
|
+
agent_id: str,
|
|
1756
|
+
user_id: Optional[str],
|
|
1757
|
+
) -> tuple[str, list[Any]]:
|
|
1758
|
+
"""跨会话事件查询的公共 JOIN/WHERE。events 表无 agent_id 列,需 join sessions。"""
|
|
1759
|
+
conditions = [
|
|
1760
|
+
"e.namespace = $1",
|
|
1761
|
+
"s.namespace = e.namespace",
|
|
1762
|
+
"s.id = e.session_id",
|
|
1763
|
+
"s.agent_id = $2",
|
|
1764
|
+
]
|
|
1765
|
+
params: list[Any] = [self.namespace, agent_id]
|
|
1766
|
+
if user_id is not None:
|
|
1767
|
+
params.append(user_id)
|
|
1768
|
+
conditions.append(f"s.user_id = ${len(params)}")
|
|
1769
|
+
where_clause = " AND ".join(conditions)
|
|
1770
|
+
from_clause = (
|
|
1771
|
+
f"FROM {KSADK_PG_EVENTS_TABLE} e "
|
|
1772
|
+
f"JOIN {KSADK_PG_SESSIONS_TABLE} s "
|
|
1773
|
+
"ON s.namespace = e.namespace AND s.id = e.session_id "
|
|
1774
|
+
f"WHERE {where_clause}"
|
|
1775
|
+
)
|
|
1776
|
+
return from_clause, params
|
|
1777
|
+
|
|
1778
|
+
async def get_events_for_agent(
|
|
1779
|
+
self,
|
|
1780
|
+
agent_id: str,
|
|
1781
|
+
user_id: Optional[str] = None,
|
|
1782
|
+
offset: Optional[int] = None,
|
|
1783
|
+
limit: Optional[int] = None,
|
|
1784
|
+
) -> list[SessionEvent]:
|
|
1785
|
+
await self._ensure_schema()
|
|
1786
|
+
from_clause, params = self._agent_events_query_parts(agent_id, user_id)
|
|
1787
|
+
columns = (
|
|
1788
|
+
"e.id, e.session_id, e.author, e.event_type, e.content_json, e.timestamp, "
|
|
1789
|
+
"e.state_delta_json, e.seq_id, e.invocation_id, e.metadata_json"
|
|
1790
|
+
)
|
|
1791
|
+
async with self._connection() as connection:
|
|
1792
|
+
if limit is not None or offset is not None:
|
|
1793
|
+
# 与 get_events 一致的"最新 N 条"尾部语义:先 DESC 取窗口再 ASC 重排
|
|
1794
|
+
if limit is not None:
|
|
1795
|
+
params.append(limit)
|
|
1796
|
+
limit_sql = f"LIMIT ${len(params)}"
|
|
1797
|
+
else:
|
|
1798
|
+
limit_sql = ""
|
|
1799
|
+
params.append(offset or 0)
|
|
1800
|
+
offset_sql = f"OFFSET ${len(params)}"
|
|
1801
|
+
query = f"""
|
|
1802
|
+
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
1803
|
+
state_delta_json, seq_id, invocation_id, metadata_json
|
|
1804
|
+
FROM (
|
|
1805
|
+
SELECT {columns}
|
|
1806
|
+
{from_clause}
|
|
1807
|
+
ORDER BY e.timestamp DESC, e.seq_id DESC, e.id DESC
|
|
1808
|
+
{limit_sql} {offset_sql}
|
|
1809
|
+
) AS latest_events
|
|
1810
|
+
ORDER BY timestamp ASC, seq_id ASC, id ASC
|
|
1811
|
+
"""
|
|
1812
|
+
else:
|
|
1813
|
+
query = f"""
|
|
1814
|
+
SELECT {columns}
|
|
1815
|
+
{from_clause}
|
|
1816
|
+
ORDER BY e.timestamp ASC, e.seq_id ASC, e.id ASC
|
|
1817
|
+
"""
|
|
1818
|
+
rows = await connection.fetch(query, *params)
|
|
1819
|
+
return [self._event_from_row(row) for row in rows]
|
|
1820
|
+
|
|
1821
|
+
async def count_events_for_agent(
|
|
1822
|
+
self,
|
|
1823
|
+
agent_id: str,
|
|
1824
|
+
user_id: Optional[str] = None,
|
|
1825
|
+
) -> int:
|
|
1826
|
+
await self._ensure_schema()
|
|
1827
|
+
from_clause, params = self._agent_events_query_parts(agent_id, user_id)
|
|
1828
|
+
async with self._connection() as connection:
|
|
1829
|
+
query = f"SELECT COUNT(*) AS total {from_clause}"
|
|
1830
|
+
return int(await connection.fetchval(query, *params) or 0)
|
|
1831
|
+
|
|
892
1832
|
async def get_state(
|
|
893
1833
|
self,
|
|
894
1834
|
agent_id: str,
|