agentengine-sdk-python 0.8.4__py3-none-any.whl → 0.8.6__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.4.dist-info → agentengine_sdk_python-0.8.6.dist-info}/METADATA +17 -10
- agentengine_sdk_python-0.8.6.dist-info/RECORD +1731 -0
- ksadk/_async_iterators.py +79 -0
- ksadk/_build_provenance.json +1 -1
- ksadk/_model_anthropic.py +49 -0
- ksadk/_model_input.py +86 -0
- ksadk/_model_json.py +40 -0
- ksadk/_model_reasoning.py +17 -0
- ksadk/_model_refusal.py +20 -0
- ksadk/_model_sse.py +163 -0
- ksadk/_process.py +83 -0
- ksadk/_str_enum.py +17 -0
- ksadk/a2a/__init__.py +157 -167
- ksadk/a2a/_invocation_state.py +86 -0
- ksadk/a2a/_space_client_events.py +33 -22
- ksadk/a2a/adk.py +194 -0
- ksadk/a2a/adk_invocation_context.py +242 -0
- ksadk/a2a/adk_runtime.py +126 -0
- ksadk/a2a/adk_tools.py +319 -0
- ksadk/a2a/bootstrap.py +149 -23
- ksadk/a2a/build_validation.py +147 -0
- ksadk/a2a/card.py +23 -15
- ksadk/a2a/codex.py +160 -0
- ksadk/a2a/codex_checkpoint.py +111 -0
- ksadk/a2a/codex_recovery.py +96 -0
- ksadk/a2a/codex_recovery_events.py +123 -0
- ksadk/a2a/codex_runtime.py +198 -0
- ksadk/a2a/codex_session_checkpoint.py +162 -0
- ksadk/a2a/composition.py +88 -0
- ksadk/a2a/context_store.py +118 -19
- ksadk/a2a/control_plane.py +108 -106
- ksadk/a2a/event_adapter.py +92 -193
- ksadk/a2a/executor.py +257 -85
- ksadk/a2a/exposure.py +106 -0
- ksadk/a2a/external_transport.py +3 -4
- ksadk/a2a/identity.py +106 -12
- ksadk/a2a/ids.py +14 -3
- ksadk/a2a/inbound_kernel.py +133 -0
- ksadk/a2a/interaction_wire.py +76 -0
- ksadk/a2a/invocation_checkpoint.py +274 -0
- ksadk/a2a/invocation_policy.py +87 -0
- ksadk/a2a/invocation_publication.py +210 -0
- ksadk/a2a/invocation_service.py +972 -0
- ksadk/a2a/invocation_types.py +459 -0
- ksadk/a2a/kernel_task_adapter.py +259 -0
- ksadk/a2a/langgraph.py +20 -7
- ksadk/a2a/langgraph_invocation_context.py +136 -0
- ksadk/a2a/langgraph_managed.py +150 -0
- ksadk/a2a/langgraph_recovery.py +32 -0
- ksadk/a2a/langgraph_runtime.py +89 -0
- ksadk/a2a/langgraph_tool_runtime.py +132 -0
- ksadk/a2a/langgraph_tools.py +63 -0
- ksadk/a2a/message_digest.py +40 -0
- ksadk/a2a/platform.py +389 -0
- ksadk/a2a/policy_refs.py +13 -0
- ksadk/a2a/presentation.py +402 -0
- ksadk/a2a/product_kernel_facts.py +177 -0
- ksadk/a2a/product_key.py +99 -0
- ksadk/a2a/protocol_errors.py +116 -0
- ksadk/a2a/result_text.py +49 -0
- ksadk/a2a/resume_store.py +93 -3
- ksadk/a2a/routes.py +6 -1
- ksadk/a2a/runtime_approval.py +198 -0
- ksadk/a2a/runtime_input.py +151 -0
- ksadk/a2a/server.py +16 -7
- ksadk/a2a/space_client.py +101 -16
- ksadk/a2a/task_adapter.py +19 -5
- ksadk/a2a/task_event_dispatcher.py +39 -2
- ksadk/a2a/task_event_outbox.py +215 -0
- ksadk/a2a/task_event_outbox_owned.py +130 -0
- ksadk/a2a/task_store.py +37 -0
- ksadk/a2a/tool_activity.py +176 -0
- ksadk/a2a/workload_tokens.py +134 -0
- ksadk/a2ui/core.py +3 -3
- ksadk/api/client.py +38 -79
- ksadk/api/sse_stream.py +96 -0
- ksadk/builders/code_builder.py +121 -118
- ksadk/builders/container_builder.py +11 -29
- ksadk/builders/framework_requirements.py +22 -2
- ksadk/builders/managed_runtime_builder.py +12 -0
- ksadk/builders/source_provenance.py +87 -0
- ksadk/cli/__init__.py +36 -0
- ksadk/cli/cmd_a2a.py +43 -0
- ksadk/cli/cmd_build.py +9 -0
- ksadk/cli/cmd_config.py +4 -4
- ksadk/cli/cmd_create.py +12 -12
- ksadk/cli/cmd_deploy.py +27 -2
- ksadk/cli/cmd_hermes.py +24 -2
- ksadk/cli/cmd_invoke.py +64 -88
- ksadk/cli/cmd_openclaw.py +26 -1
- ksadk/cli/cmd_plugin.py +70 -12
- ksadk/cli/cmd_studio.py +69 -17
- ksadk/cli/cmd_web.py +2 -0
- ksadk/cli/hosted_invoke.py +206 -0
- ksadk/cli/invoke_content.py +60 -0
- ksadk/cli/openclaw_env.py +1 -1
- ksadk/cli/resource_common.py +26 -0
- ksadk/cli/runtime_bootstrap.py +27 -5
- ksadk/codex/_expert_request_reader.py +48 -0
- ksadk/codex/a2a_tools.py +140 -0
- ksadk/codex/async_approval.py +169 -0
- ksadk/codex/async_client.py +938 -0
- ksadk/codex/async_proxy.py +216 -0
- ksadk/codex/base_runtime.py +25 -0
- ksadk/codex/client.py +3 -1047
- ksadk/codex/client_payloads.py +85 -0
- ksadk/codex/rollout_checkpoint.py +264 -0
- ksadk/codex/runtime.py +290 -54
- ksadk/common/auth.py +2 -2
- ksadk/common/cloud_headers.py +36 -0
- ksadk/common/diagnostics.py +34 -0
- ksadk/common/kop_client.py +2 -1
- ksadk/configs/__init__.py +1 -1
- ksadk/configs/env_registry.py +216 -143
- ksadk/configs/env_registry_a2a.py +173 -0
- ksadk/configs/env_registry_studio.py +134 -0
- ksadk/configs/global_config.py +2 -1
- ksadk/configs/settings.py +9 -3
- ksadk/connector/__init__.py +17 -0
- ksadk/connector/channel.py +477 -0
- ksadk/context_engine/assembler.py +9 -0
- ksadk/context_engine/capabilities.py +52 -4
- ksadk/context_engine/contributors.py +80 -17
- ksadk/context_engine/instruction_authority.py +18 -0
- ksadk/conversations/attachment_storage.py +10 -3
- ksadk/conversations/attachments.py +69 -20
- ksadk/conversations/contracts.py +28 -9
- ksadk/conversations/message_projection.py +51 -155
- ksadk/conversations/message_projection_blocks.py +137 -0
- ksadk/conversations/model_context.py +11 -3
- ksadk/conversations/normalize.py +28 -10
- ksadk/conversations/projector.py +63 -0
- ksadk/conversations/runtime_baseline.py +37 -0
- ksadk/conversations/runtime_compaction.py +7 -2
- ksadk/conversations/runtime_input.py +16 -4
- ksadk/conversations/runtime_invocation.py +17 -4
- ksadk/conversations/runtime_observability.py +39 -10
- ksadk/conversations/runtime_payloads.py +12 -0
- ksadk/conversations/runtime_persistence.py +296 -32
- ksadk/conversations/runtime_preparation.py +98 -13
- ksadk/conversations/runtime_projection.py +217 -0
- ksadk/conversations/runtime_resume.py +141 -70
- ksadk/conversations/runtime_stream_events.py +29 -35
- ksadk/conversations/runtime_streaming.py +8 -0
- ksadk/conversations/tool_receipt_resume.py +387 -0
- ksadk/conversations/tool_receipts.py +32 -0
- ksadk/deployment/env_forward.py +5 -0
- ksadk/deployment/manager.py +15 -6
- ksadk/deployment/providers/serverless.py +76 -136
- ksadk/deployment/providers/serverless_payloads.py +122 -0
- ksadk/evaluation/agent_eval_client.py +2 -1
- ksadk/evaluation/contracts.py +78 -3
- ksadk/evaluation/evaluators.py +166 -1
- ksadk/evaluation/evidence.py +271 -4
- ksadk/evaluation/local_adapter.py +76 -12
- ksadk/evaluation/studio_build_adapter.py +73 -9
- ksadk/events/adapters/_a2a_checkpoint.py +151 -0
- ksadk/events/adapters/_a2a_snapshot.py +18 -14
- ksadk/events/adapters/_a2a_support.py +15 -3
- ksadk/events/adapters/_a2a_tool_activity.py +123 -0
- ksadk/events/adapters/_codex_errors.py +49 -0
- ksadk/events/adapters/_codex_items.py +16 -8
- ksadk/events/adapters/_langgraph_support.py +46 -1
- ksadk/events/adapters/a2a.py +54 -26
- ksadk/events/adapters/adk.py +188 -30
- ksadk/events/adapters/codex.py +33 -7
- ksadk/events/adapters/langgraph.py +16 -6
- ksadk/events/canonical.py +5 -0
- ksadk/events/canonical_store.py +200 -4
- ksadk/events/reducer.py +82 -0
- ksadk/events/run_authority.py +176 -0
- ksadk/events/session_event.py +2 -2
- ksadk/harness/__init__.py +18 -0
- ksadk/harness/app.py +11 -0
- ksadk/harness/artifact_adapters/__init__.py +1 -0
- ksadk/harness/artifact_adapters/native_page_budget.py +172 -0
- ksadk/harness/artifact_adapters/native_search.py +249 -0
- ksadk/harness/artifact_adapters/native_search_budget.py +134 -0
- ksadk/harness/artifact_adapters/native_store.py +115 -0
- ksadk/harness/artifact_adapters/native_tool.py +222 -0
- ksadk/harness/artifact_store.py +230 -0
- ksadk/harness/browser_adapters/__init__.py +6 -0
- ksadk/harness/browser_adapters/native_browser_tool.py +92 -0
- ksadk/harness/browser_adapters/native_dom_snapshot.py +187 -0
- ksadk/harness/browser_adapters/native_playwright.py +953 -0
- ksadk/harness/browser_adapters/native_vision.py +295 -0
- ksadk/harness/capabilities.py +115 -0
- ksadk/harness/capability_adapters/__init__.py +1 -0
- ksadk/harness/capability_adapters/native_dsh.py +289 -0
- ksadk/harness/capability_runtime.py +332 -0
- ksadk/harness/closure_contract.py +92 -0
- ksadk/harness/compaction_record.py +153 -0
- ksadk/harness/compiler.py +284 -0
- ksadk/harness/config.py +28 -5
- ksadk/harness/conformance/__init__.py +33 -0
- ksadk/harness/conformance/contract.py +504 -0
- ksadk/harness/conformance/fixtures.py +102 -0
- ksadk/harness/context_engine.py +388 -0
- ksadk/harness/context_maintenance.py +259 -0
- ksadk/harness/context_manifest.py +188 -0
- ksadk/harness/context_sections.py +397 -0
- ksadk/harness/context_tuning.py +168 -0
- ksadk/harness/diagnostic_adapters/__init__.py +1 -0
- ksadk/harness/diagnostic_adapters/contracts.py +70 -0
- ksadk/harness/diagnostic_adapters/lsp_rpc.py +210 -0
- ksadk/harness/diagnostic_adapters/native_lsp.py +286 -0
- ksadk/harness/draft_runtime.py +322 -0
- ksadk/harness/engine/__init__.py +40 -0
- ksadk/harness/engine/base.py +122 -0
- ksadk/harness/engine/budgets.py +108 -0
- ksadk/harness/engine/capability_declarations.py +59 -0
- ksadk/harness/engine/completion_guard.py +57 -0
- ksadk/harness/engine/context_pipeline.py +1351 -0
- ksadk/harness/engine/graph_builder.py +352 -0
- ksadk/harness/engine/hooked_reasoner.py +380 -0
- ksadk/harness/engine/langgraph.py +1049 -0
- ksadk/harness/engine/mcp_disclosure.py +701 -0
- ksadk/harness/engine/phases/__init__.py +6 -0
- ksadk/harness/engine/phases/context.py +48 -0
- ksadk/harness/engine/phases/interaction.py +31 -0
- ksadk/harness/engine/phases/reason.py +552 -0
- ksadk/harness/engine/phases/tools.py +638 -0
- ksadk/harness/engine/policy_runtime.py +81 -0
- ksadk/harness/engine/postgres_checkpointer.py +386 -0
- ksadk/harness/engine/run_control_bridge.py +100 -0
- ksadk/harness/engine/run_types.py +98 -0
- ksadk/harness/engine/skill_disclosure.py +275 -0
- ksadk/harness/engine/spans.py +41 -0
- ksadk/harness/engine/steering.py +177 -0
- ksadk/harness/engine/subagents.py +360 -0
- ksadk/harness/engine/thread_ids.py +112 -0
- ksadk/harness/engine/tool_dispatch.py +249 -0
- ksadk/harness/event_tree.py +212 -0
- ksadk/harness/events.py +498 -0
- ksadk/harness/execution_policy.py +104 -0
- ksadk/harness/hooks.py +259 -0
- ksadk/harness/insights.py +210 -0
- ksadk/harness/lifecycle.py +578 -0
- ksadk/harness/lifecycle_conformance.py +233 -0
- ksadk/harness/lifecycle_local_plane.py +104 -0
- ksadk/harness/loop/__init__.py +44 -0
- ksadk/harness/loop/reason.py +699 -0
- ksadk/harness/loop/tools.py +907 -0
- ksadk/harness/managed_runtime.py +1044 -0
- ksadk/harness/mcp_disclosure_contract.py +85 -0
- ksadk/harness/mcp_matrix.py +474 -0
- ksadk/harness/mcp_result_policy.py +44 -0
- ksadk/harness/mcp_runtime.py +504 -0
- ksadk/harness/memory_consolidation.py +157 -0
- ksadk/harness/memory_loop.py +156 -0
- ksadk/harness/memory_runtime.py +541 -0
- ksadk/harness/metrics.py +90 -0
- ksadk/harness/micro_compact.py +69 -0
- ksadk/harness/model_adapters/__init__.py +1 -0
- ksadk/harness/model_adapters/native_mcp_media.py +100 -0
- ksadk/harness/model_adapters/native_mcp_result.py +36 -0
- ksadk/harness/model_adapters/native_openai.py +703 -0
- ksadk/harness/model_capability.py +468 -0
- ksadk/harness/model_provider.py +430 -0
- ksadk/harness/multimodal.py +57 -0
- ksadk/harness/native/__init__.py +1 -0
- ksadk/harness/native/activation_contract.py +25 -0
- ksadk/harness/native/activation_recovery.py +29 -0
- ksadk/harness/native/adapters.py +291 -0
- ksadk/harness/native/artifact_contract.py +14 -0
- ksadk/harness/native/artifact_partial_read_capacity.py +171 -0
- ksadk/harness/native/artifact_read_capacity.py +182 -0
- ksadk/harness/native/artifact_read_contract.py +27 -0
- ksadk/harness/native/artifact_runtime.py +408 -0
- ksadk/harness/native/artifact_search_capacity.py +206 -0
- ksadk/harness/native/artifact_search_contract.py +40 -0
- ksadk/harness/native/artifact_single_read_capacity.py +170 -0
- ksadk/harness/native/browser_contract.py +229 -0
- ksadk/harness/native/browser_recovery.py +183 -0
- ksadk/harness/native/capabilities.py +204 -0
- ksadk/harness/native/child_approval.py +60 -0
- ksadk/harness/native/child_budget.py +136 -0
- ksadk/harness/native/child_cancellation.py +80 -0
- ksadk/harness/native/child_input.py +98 -0
- ksadk/harness/native/child_input_runtime.py +59 -0
- ksadk/harness/native/child_interruption.py +81 -0
- ksadk/harness/native/child_lifecycle.py +246 -0
- ksadk/harness/native/child_lifecycle_contract.py +91 -0
- ksadk/harness/native/child_notifications.py +75 -0
- ksadk/harness/native/child_promotion.py +66 -0
- ksadk/harness/native/command_runtime.py +99 -0
- ksadk/harness/native/completion.py +302 -0
- ksadk/harness/native/completion_text.py +116 -0
- ksadk/harness/native/context.py +358 -0
- ksadk/harness/native/context_artifact_page.py +75 -0
- ksadk/harness/native/context_compaction_projection.py +131 -0
- ksadk/harness/native/context_contributions.py +320 -0
- ksadk/harness/native/context_contributor_contract.py +133 -0
- ksadk/harness/native/context_driver.py +820 -0
- ksadk/harness/native/context_fresh_tools.py +49 -0
- ksadk/harness/native/context_history.py +272 -0
- ksadk/harness/native/context_microcompact.py +61 -0
- ksadk/harness/native/context_partial_summary.py +58 -0
- ksadk/harness/native/context_partition.py +492 -0
- ksadk/harness/native/context_pruning.py +275 -0
- ksadk/harness/native/context_reduction.py +60 -0
- ksadk/harness/native/context_replay.py +148 -0
- ksadk/harness/native/context_request_projection.py +526 -0
- ksadk/harness/native/context_runtime.py +976 -0
- ksadk/harness/native/context_runtime_contracts.py +409 -0
- ksadk/harness/native/context_search.py +112 -0
- ksadk/harness/native/context_source_fragments.py +188 -0
- ksadk/harness/native/context_source_progress.py +119 -0
- ksadk/harness/native/context_summary_planning.py +788 -0
- ksadk/harness/native/context_summary_recovery.py +105 -0
- ksadk/harness/native/delivery_review.py +331 -0
- ksadk/harness/native/delivery_review_contract.py +54 -0
- ksadk/harness/native/effect_admission.py +82 -0
- ksadk/harness/native/effect_control.py +318 -0
- ksadk/harness/native/effect_receipts.py +729 -0
- ksadk/harness/native/effect_runtime.py +303 -0
- ksadk/harness/native/effective_configuration.py +28 -0
- ksadk/harness/native/engine.py +945 -0
- ksadk/harness/native/final_output.py +34 -0
- ksadk/harness/native/final_submission.py +58 -0
- ksadk/harness/native/finalization_workspace.py +96 -0
- ksadk/harness/native/fork.py +151 -0
- ksadk/harness/native/guidance.py +91 -0
- ksadk/harness/native/history.py +381 -0
- ksadk/harness/native/hook_executor.py +205 -0
- ksadk/harness/native/hook_runtime_contract.py +282 -0
- ksadk/harness/native/interaction_observation.py +117 -0
- ksadk/harness/native/lease.py +103 -0
- ksadk/harness/native/machine.py +974 -0
- ksadk/harness/native/mcp_result_governance.py +156 -0
- ksadk/harness/native/model.py +570 -0
- ksadk/harness/native/model_feedback.py +63 -0
- ksadk/harness/native/model_input.py +30 -0
- ksadk/harness/native/model_recovery_contract.py +35 -0
- ksadk/harness/native/model_replay.py +128 -0
- ksadk/harness/native/model_request.py +133 -0
- ksadk/harness/native/model_runtime.py +196 -0
- ksadk/harness/native/model_takeover.py +419 -0
- ksadk/harness/native/model_tool_batch.py +40 -0
- ksadk/harness/native/observed_progress.py +46 -0
- ksadk/harness/native/operator_guidance.py +201 -0
- ksadk/harness/native/output_contract.py +80 -0
- ksadk/harness/native/output_recovery.py +24 -0
- ksadk/harness/native/ports.py +749 -0
- ksadk/harness/native/precompact_hook_runtime.py +171 -0
- ksadk/harness/native/replay_context.py +149 -0
- ksadk/harness/native/request_media.py +112 -0
- ksadk/harness/native/restore_contract.py +16 -0
- ksadk/harness/native/run_clock.py +120 -0
- ksadk/harness/native/state.py +436 -0
- ksadk/harness/native/steering.py +170 -0
- ksadk/harness/native/stop_hook_runtime.py +151 -0
- ksadk/harness/native/studio_admission.py +29 -0
- ksadk/harness/native/subagents.py +86 -0
- ksadk/harness/native/task_policy.py +99 -0
- ksadk/harness/native/task_progress.py +86 -0
- ksadk/harness/native/terminal_verification.py +43 -0
- ksadk/harness/native/tool_argument_feedback.py +178 -0
- ksadk/harness/native/tool_budget.py +253 -0
- ksadk/harness/native/tool_error_streak.py +89 -0
- ksadk/harness/native/tool_hook_runtime.py +343 -0
- ksadk/harness/native/tool_input_validation.py +58 -0
- ksadk/harness/native/tool_interruption.py +96 -0
- ksadk/harness/native/tool_observation.py +259 -0
- ksadk/harness/native/tool_progress.py +223 -0
- ksadk/harness/native/tool_recovery.py +25 -0
- ksadk/harness/native/tool_scheduling.py +33 -0
- ksadk/harness/native/tool_schema.py +126 -0
- ksadk/harness/native/transitions.py +151 -0
- ksadk/harness/native/turn_control.py +98 -0
- ksadk/harness/native/user_document.py +98 -0
- ksadk/harness/native/user_document_capture.py +49 -0
- ksadk/harness/native/user_input.py +87 -0
- ksadk/harness/native/verification.py +432 -0
- ksadk/harness/native/verification_binding.py +40 -0
- ksadk/harness/native/verification_runtime.py +233 -0
- ksadk/harness/native/verification_workspace.py +67 -0
- ksadk/harness/native_driver_failure.py +123 -0
- ksadk/harness/native_facade.py +977 -0
- ksadk/harness/native_factory.py +244 -0
- ksadk/harness/native_projection.py +503 -0
- ksadk/harness/native_runtime.py +621 -0
- ksadk/harness/native_shadow.py +250 -0
- ksadk/harness/native_shadow_inputs.py +146 -0
- ksadk/harness/observability/__init__.py +29 -0
- ksadk/harness/observability/inspection.py +528 -0
- ksadk/harness/observability/metrics.py +167 -0
- ksadk/harness/observability/otel_exporter.py +218 -0
- ksadk/harness/progress_adapters/__init__.py +5 -0
- ksadk/harness/progress_adapters/native_todo.py +75 -0
- ksadk/harness/prompt_cache.py +132 -0
- ksadk/harness/public_activity.py +213 -0
- ksadk/harness/public_output.py +30 -0
- ksadk/harness/public_summary.py +36 -0
- ksadk/harness/readiness.py +249 -0
- ksadk/harness/reasoner.py +779 -17
- ksadk/harness/release_readiness.py +140 -0
- ksadk/harness/resource_ref.py +69 -0
- ksadk/harness/rpc.py +200 -0
- ksadk/harness/run_control.py +773 -0
- ksadk/harness/runtime.py +157 -113
- ksadk/harness/runtime_capabilities.py +228 -0
- ksadk/harness/runtime_server.py +514 -0
- ksadk/harness/sandbox_adapters.py +739 -0
- ksadk/harness/sandbox_backend.py +733 -0
- ksadk/harness/sandbox_conformance.py +288 -0
- ksadk/harness/sandbox_lease.py +77 -0
- ksadk/harness/sandbox_lease_conformance.py +259 -0
- ksadk/harness/sandbox_matrix.py +170 -0
- ksadk/harness/sandbox_reconciliation.py +140 -0
- ksadk/harness/sandbox_recovery.py +586 -0
- ksadk/harness/sandbox_recovery_conformance.py +246 -0
- ksadk/harness/sdk.py +153 -0
- ksadk/harness/session_store.py +589 -0
- ksadk/harness/skill_adapters/__init__.py +1 -0
- ksadk/harness/skill_adapters/native_bundle.py +148 -0
- ksadk/harness/skill_adapters/native_disclosure.py +306 -0
- ksadk/harness/skill_composition.py +212 -0
- ksadk/harness/skill_feedback.py +123 -0
- ksadk/harness/skill_intent.py +47 -0
- ksadk/harness/skill_matrix.py +233 -0
- ksadk/harness/skill_runtime.py +317 -0
- ksadk/harness/spec.py +342 -0
- ksadk/harness/state.py +155 -0
- ksadk/harness/stores/__init__.py +14 -0
- ksadk/harness/stores/native_command_settlement.py +65 -0
- ksadk/harness/stores/native_contract.py +311 -0
- ksadk/harness/stores/native_memory.py +326 -0
- ksadk/harness/stores/native_memory_archive.py +70 -0
- ksadk/harness/stores/native_migration_cli.py +91 -0
- ksadk/harness/stores/native_outbox.py +56 -0
- ksadk/harness/stores/native_sqlite.py +782 -0
- ksadk/harness/stores/native_sqlite_audit.py +29 -0
- ksadk/harness/stores/native_sqlite_migration.py +252 -0
- ksadk/harness/strategies.py +149 -0
- ksadk/harness/subagent.py +263 -0
- ksadk/harness/subagent_adapters/checkpoint_recovery.py +120 -0
- ksadk/harness/subagent_adapters/native_background_child.py +803 -0
- ksadk/harness/subagent_adapters/native_child.py +819 -0
- ksadk/harness/subagent_adapters/native_child_approval.py +128 -0
- ksadk/harness/subagent_adapters/native_child_continuation.py +51 -0
- ksadk/harness/subagent_adapters/native_child_result.py +392 -0
- ksadk/harness/subagent_adapters/prepared_recovery.py +120 -0
- ksadk/harness/tool_display.py +75 -0
- ksadk/harness/tool_display_contract.py +134 -0
- ksadk/harness/tool_output.py +141 -0
- ksadk/harness/tool_policy.py +134 -0
- ksadk/harness/tool_receipts.py +96 -0
- ksadk/harness/tool_reliability.py +81 -0
- ksadk/harness/tool_result_policy.py +216 -0
- ksadk/harness/tools.py +52 -0
- ksadk/harness/user_errors.py +69 -0
- ksadk/harness/working_context.py +81 -0
- ksadk/harness/working_context_patch.py +99 -0
- ksadk/harness/workspace_adapters/__init__.py +6 -0
- ksadk/harness/workspace_adapters/native_directory.py +180 -0
- ksadk/harness/workspace_adapters/native_git.py +208 -0
- ksadk/harness/workspace_adapters/native_isolation.py +350 -0
- ksadk/identity/resolver.py +18 -0
- ksadk/interaction/__init__.py +1 -1
- ksadk/interaction/ledger.py +1 -1
- ksadk/interaction/provider.py +1 -1
- ksadk/interaction/providers/__init__.py +3 -1
- ksadk/interaction/providers/adk.py +1 -1
- ksadk/interaction/providers/codex.py +1 -1
- ksadk/interaction/providers/harness.py +50 -0
- ksadk/interaction/providers/langgraph.py +9 -2
- ksadk/kernel/__init__.py +10 -0
- ksadk/kernel/approval_presentation.py +91 -0
- ksadk/kernel/authorization.py +1 -1
- ksadk/kernel/bootstrap.py +220 -252
- ksadk/kernel/contract_fingerprints.py +45 -1
- ksadk/kernel/contracts.py +30 -0
- ksadk/kernel/control.py +180 -29
- ksadk/kernel/execution_grants.py +428 -0
- ksadk/kernel/execution_grants_memory.py +252 -0
- ksadk/kernel/execution_grants_postgres.py +395 -0
- ksadk/kernel/execution_grants_sqlite.py +435 -0
- ksadk/kernel/execution_host_ingress.py +1071 -0
- ksadk/kernel/history_projection.py +120 -0
- ksadk/kernel/ingress.py +139 -226
- ksadk/kernel/ingress_bootstrap.py +268 -0
- ksadk/kernel/legacy_history.py +179 -0
- ksadk/kernel/mapping.py +1 -1
- ksadk/kernel/memory_store.py +61 -58
- ksadk/kernel/memory_store_projection.py +63 -0
- ksadk/kernel/postgres_event_log.py +181 -0
- ksadk/kernel/postgres_store.py +230 -231
- ksadk/kernel/readiness.py +125 -0
- ksadk/kernel/recovery.py +166 -16
- ksadk/kernel/recovery_projection.py +124 -0
- ksadk/kernel/runtime_checkpoint.py +34 -0
- ksadk/kernel/sql/001_agent_kernel.sql +28 -0
- ksadk/kernel/sqlite_schema.py +100 -0
- ksadk/kernel/sqlite_store.py +410 -200
- ksadk/kernel/state.py +2 -3
- ksadk/kernel/store.py +104 -5
- ksadk/kernel/teams_artifact_tools.py +392 -0
- ksadk/kernel/teams_effects.py +851 -0
- ksadk/kernel/teams_execution_context.py +408 -0
- ksadk/kernel/teams_host_http.py +237 -0
- ksadk/kernel/teams_material_transport.py +245 -0
- ksadk/kernel/teams_materials.py +318 -0
- ksadk/kernel/teams_runtime_bootstrap.py +604 -0
- ksadk/kernel/teams_tool_runtime.py +273 -0
- ksadk/kernel/teams_workspace.py +259 -0
- ksadk/kernel/worker.py +369 -340
- ksadk/kernel/worker_controls.py +454 -0
- ksadk/kernel/worker_history.py +72 -0
- ksadk/kernel/worker_identity.py +74 -0
- ksadk/kernel/worker_interactions.py +197 -0
- ksadk/knowledge_base/client.py +15 -1
- ksadk/managed_runtime.py +29 -2
- ksadk/memory/adk/backends/http_ltm_backend.py +2 -1
- ksadk/memory/adk/backends/sdk_ltm_backend.py +15 -1
- ksadk/memory/adk/bounded_database_session_service.py +232 -0
- ksadk/memory/adk/resilient_session_service.py +115 -15
- ksadk/memory/adk/short_term_memory.py +8 -9
- ksadk/memory/coordinator.py +22 -6
- ksadk/memory/extraction.py +159 -7
- ksadk/memory/models.py +77 -1
- ksadk/memory/provider_resolver.py +5 -0
- ksadk/memory/providers/local_candidates.py +183 -0
- ksadk/memory/providers/local_postgres.py +200 -0
- ksadk/memory/providers/local_sqlite.py +280 -67
- ksadk/memory/resolved_policy.py +12 -7
- ksadk/memory/retrieval.py +189 -0
- ksadk/memory/store_adapter.py +150 -0
- ksadk/model_gateway/__init__.py +29 -0
- ksadk/model_gateway/client.py +253 -0
- ksadk/model_gateway/events.py +113 -0
- ksadk/model_gateway/matrix.py +297 -0
- ksadk/model_policy.py +2 -2
- ksadk/model_proxy/compat.py +670 -0
- ksadk/model_proxy/detect.py +254 -0
- ksadk/model_proxy/server.py +14 -9
- ksadk/model_proxy/transform.py +72 -6
- ksadk/plugins/__init__.py +1 -1
- ksadk/plugins/bridges/dsh.py +29 -20
- ksadk/plugins/bridges/dsh_profile_manifest.py +36 -0
- ksadk/plugins/builtin_resources.py +199 -0
- ksadk/plugins/builtins.py +417 -185
- ksadk/plugins/companion_artifacts.py +83 -0
- ksadk/plugins/companions.py +368 -0
- ksadk/plugins/context_contributor.py +15 -4
- ksadk/plugins/contracts.py +1 -1
- ksadk/plugins/dsh_channels.py +156 -0
- ksadk/plugins/dsh_dependency_policy.py +41 -0
- ksadk/plugins/dsh_home.py +140 -0
- ksadk/plugins/dsh_teams.py +105 -0
- ksadk/plugins/dsh_toolchain.py +92 -21
- ksadk/plugins/execution_host.py +107 -0
- ksadk/plugins/host.py +73 -5
- ksadk/plugins/kernel_adapter.py +44 -1
- ksadk/plugins/memory_provider.py +180 -0
- ksadk/plugins/providers/_process_group.py +50 -0
- ksadk/plugins/providers/bundles/dsh-channels-client/client.js +19 -0
- ksadk/plugins/providers/bundles/dsh-channels-client/cordis.patch.yml +3 -0
- ksadk/plugins/providers/bundles/dsh-channels-client/index.mjs +7 -0
- ksadk/plugins/providers/bundles/dsh-channels-client/package.json +12 -0
- ksadk/plugins/providers/bundles/dsh-knowledge/index.mjs +24 -2
- ksadk/plugins/providers/bundles/dsh-knowledge/package.json +1 -1
- ksadk/plugins/providers/bundles/dsh-memory/package.json +1 -1
- ksadk/plugins/providers/bundles/dsh-skill-center/package.json +1 -1
- ksadk/plugins/providers/bundles/dsh-teams-client/client.js +29 -0
- ksadk/plugins/providers/bundles/dsh-teams-client/cordis.patch.yml +3 -0
- ksadk/plugins/providers/bundles/dsh-teams-client/index.mjs +11 -0
- ksadk/plugins/providers/bundles/dsh-teams-client/package.json +35 -0
- ksadk/plugins/providers/bundles/dsh-teams-leader-policy/cordis.patch.yml +3 -0
- ksadk/plugins/providers/bundles/dsh-teams-leader-policy/index.mjs +13 -0
- ksadk/plugins/providers/bundles/dsh-teams-leader-policy/package.json +27 -0
- ksadk/plugins/providers/bundles/dsh-teams-profile/cordis.patch.yml +3 -0
- ksadk/plugins/providers/bundles/dsh-teams-profile/index.mjs +12 -0
- ksadk/plugins/providers/bundles/dsh-teams-profile/package.json +26 -0
- ksadk/plugins/providers/bundles/dsh-teams-router/cordis.patch.yml +3 -0
- ksadk/plugins/providers/bundles/dsh-teams-router/index.mjs +16 -0
- ksadk/plugins/providers/bundles/dsh-teams-router/package.json +27 -0
- ksadk/plugins/providers/bundles/dsh-teams-tasks/cordis.patch.yml +3 -0
- ksadk/plugins/providers/bundles/dsh-teams-tasks/index.mjs +16 -0
- ksadk/plugins/providers/bundles/dsh-teams-tasks/package.json +27 -0
- ksadk/plugins/providers/bundles/dsh-teams-tools/cordis.patch.yml +3 -0
- ksadk/plugins/providers/bundles/dsh-teams-tools/index.mjs +25 -0
- ksadk/plugins/providers/bundles/dsh-teams-tools/package.json +29 -0
- ksadk/plugins/providers/bundles/dsh-teams-tools/tools.json +235 -0
- ksadk/plugins/providers/bundles/ksadk-codex/index.mjs +1 -1
- ksadk/plugins/providers/bundles/ksadk-dsh-capability-host/index.mjs +51 -1
- ksadk/plugins/providers/bundles/ksadk-dsh-capability-host/package.json +2 -2
- ksadk/plugins/providers/bundles/ksadk-dsh-companion-host/client.mjs +133 -0
- ksadk/plugins/providers/bundles/ksadk-dsh-companion-host/index.mjs +14 -0
- ksadk/plugins/providers/bundles/ksadk-dsh-studio/client.js +27 -4
- ksadk/plugins/providers/bundles/ksadk-dsh-studio/index.mjs +9 -5
- ksadk/plugins/providers/bundles/ksadk-harness/index.mjs +1 -1
- ksadk/plugins/providers/codex.py +52 -40
- ksadk/plugins/providers/codex_native.py +20 -0
- ksadk/plugins/providers/codex_skills.py +46 -0
- ksadk/plugins/providers/dsh_capabilities.py +49 -143
- ksadk/plugins/providers/dsh_connector_lease.py +225 -0
- ksadk/plugins/providers/dsh_mcp.py +163 -1
- ksadk/plugins/providers/harness.py +413 -52
- ksadk/plugins/providers/harness_context.py +61 -0
- ksadk/plugins/providers/harness_contributions.py +241 -0
- ksadk/plugins/providers/harness_delegation.py +670 -0
- ksadk/plugins/providers/harness_hooks.py +121 -0
- ksadk/plugins/providers/harness_managed.py +550 -0
- ksadk/plugins/providers/harness_tools.py +455 -0
- ksadk/plugins/providers/legacy_catalog.py +1 -1
- ksadk/plugins/providers/mcp_projection.py +100 -3
- ksadk/plugins/providers/platform_resources.py +16 -6
- ksadk/plugins/providers/shipped_dsh.py +4 -1
- ksadk/plugins/subagent_providers/codex.py +28 -6
- ksadk/plugins/teams/__init__.py +5 -0
- ksadk/plugins/teams/api.py +405 -0
- ksadk/plugins/teams/application.py +540 -0
- ksadk/plugins/teams/artifacts.py +60 -0
- ksadk/plugins/teams/build_artifacts.py +460 -0
- ksadk/plugins/teams/cloud_contract_fingerprints.py +22 -0
- ksadk/plugins/teams/cloud_contracts.py +928 -0
- ksadk/plugins/teams/cloud_permits.py +250 -0
- ksadk/plugins/teams/context.py +96 -0
- ksadk/plugins/teams/contracts.py +136 -0
- ksadk/plugins/teams/domain.py +1480 -0
- ksadk/plugins/teams/domain_values.py +24 -0
- ksadk/plugins/teams/effect_contracts.py +255 -0
- ksadk/plugins/teams/errors.py +13 -0
- ksadk/plugins/teams/execution_projection.py +255 -0
- ksadk/plugins/teams/leader_decisions.py +106 -0
- ksadk/plugins/teams/migration.py +311 -0
- ksadk/plugins/teams/migration_cli.py +322 -0
- ksadk/plugins/teams/postgres_store.py +352 -0
- ksadk/plugins/teams/release_contracts.py +60 -0
- ksadk/plugins/teams/runtime.py +853 -0
- ksadk/plugins/teams/source_projection.py +84 -0
- ksadk/plugins/teams/store.py +519 -0
- ksadk/plugins/teams/task_decisions.py +436 -0
- ksadk/plugins/teams/tool_service.py +152 -0
- ksadk/plugins/teams/transport.py +96 -0
- ksadk/plugins/teams/workspaces.py +255 -0
- ksadk/resource_runtime/skill_runtime.py +3 -0
- ksadk/resource_runtime/socket_server.py +11 -0
- ksadk/resource_runtime/worker.py +28 -4
- ksadk/runners/_adk_a2a_stream.py +122 -0
- ksadk/runners/_adk_canonical_stream.py +474 -0
- ksadk/runners/_langgraph_canonical_streams.py +527 -0
- ksadk/runners/_langgraph_runner_streams.py +83 -401
- ksadk/runners/_langgraph_state_reader.py +106 -0
- ksadk/runners/_langgraph_tool_projection.py +86 -0
- ksadk/runners/_langgraph_tools_transformer.py +27 -0
- ksadk/runners/_session_identity.py +285 -0
- ksadk/runners/adk_runner.py +220 -350
- ksadk/runners/base_runner.py +6 -5
- ksadk/runners/langgraph_runner.py +208 -195
- ksadk/runners/patch_langchain.py +47 -0
- ksadk/runners/usage_accumulator.py +11 -3
- ksadk/runners/utils/loader.py +28 -14
- ksadk/runtime/_runner_adapter/a2ui_surface.py +145 -0
- ksadk/runtime/_runner_adapter/gateway_approvals.py +93 -0
- ksadk/runtime/_runner_adapter/stream_mapping.py +134 -129
- ksadk/runtime/adapter.py +40 -3
- ksadk/runtime/conversation_execution.py +29 -3
- ksadk/runtime/executor.py +105 -7
- ksadk/runtime/factory.py +45 -3
- ksadk/runtime/framework_adapters.py +184 -10
- ksadk/runtime/hosted_finalizer.py +4 -6
- ksadk/runtime/launch.py +2 -0
- ksadk/runtime/preprocessing.py +11 -3
- ksadk/runtime/runner_adapter.py +160 -21
- ksadk/runtime/skill_eval_result.py +36 -0
- ksadk/runtime/timing.py +46 -0
- ksadk/runtime/usage.py +49 -18
- ksadk/runtime_context.py +105 -1
- ksadk/sandbox/backends/e2b.py +272 -24
- ksadk/sandbox/backends/local_process.py +73 -39
- ksadk/sandbox/base.py +62 -1
- ksadk/sandbox/diagnostics.py +82 -0
- ksadk/sandbox/e2b_connection.py +9 -1
- ksadk/sandbox/local_controls.py +776 -0
- ksadk/sandbox/local_launcher.py +124 -0
- ksadk/scheduler/dispatcher.py +1 -1
- ksadk/server/factory.py +178 -25
- ksadk/server/history_deadline.py +158 -0
- ksadk/server/history_page_cache.py +129 -0
- ksadk/server/invocation_identity.py +118 -0
- ksadk/server/routes/checkpoint_audit.py +88 -0
- ksadk/server/routes/checkpoint_listing.py +294 -0
- ksadk/server/routes/checkpoint_resolution.py +73 -20
- ksadk/server/routes/common.py +32 -3
- ksadk/server/routes/control.py +112 -9
- ksadk/server/routes/dependencies.py +2 -1
- ksadk/server/routes/display_projection.py +154 -0
- ksadk/server/routes/kernel_ingress.py +26 -3
- ksadk/server/routes/misc.py +331 -33
- ksadk/server/routes/models.py +28 -4
- ksadk/server/routes/openai_compat.py +82 -13
- ksadk/server/routes/projection.py +159 -216
- ksadk/server/routes/run.py +112 -37
- ksadk/server/routes/sessions.py +493 -358
- ksadk/server/routes/streaming.py +68 -15
- ksadk/server/routes/tool_receipt_claim_routes.py +107 -0
- ksadk/server/routes/workspace.py +135 -23
- ksadk/server/static/assets/{ArtifactsPanel-CGbWlMNh.js → ArtifactsPanel-CILaW-fC.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-b4C7upmO.js → CodeBlock-BVrNVtJC.js} +10 -7
- ksadk/server/static/assets/MathMessageMarkdown-Dp7c4wWD.js +8 -0
- ksadk/server/static/assets/{MermaidBlock-BEBN4Ksz.js → MermaidBlock-Dxop8Rd7.js} +9 -9
- ksadk/server/static/assets/{NativeTerminalPanel-zvL-WpAn.js → NativeTerminalPanel-Cjjz8B30.js} +1 -1
- ksadk/server/static/assets/{abnfDiagram-VCTEODGH-BYafW7Za.js → abnfDiagram-VCTEODGH-ckWDmOzw.js} +1 -1
- ksadk/server/static/assets/{arc-bTohInsS.js → arc-DqxJede-.js} +1 -1
- ksadk/server/static/assets/architecture-7GRP2DOG-pn_DuLy6.js +1 -0
- ksadk/server/static/assets/{architectureDiagram-5GKGNRK7-Ch5Lbzsi.js → architectureDiagram-5GKGNRK7-SEQA4bVi.js} +1 -1
- ksadk/server/static/assets/{blockDiagram-NRAW4CY4-kqF4MDOG.js → blockDiagram-NRAW4CY4-pM0B-6NJ.js} +1 -1
- ksadk/server/static/assets/{c4Diagram-UCG6FXSJ-8uSRIODv.js → c4Diagram-UCG6FXSJ-m2tuCNVq.js} +1 -1
- ksadk/server/static/assets/channel-fySsnkft.js +1 -0
- ksadk/server/static/assets/chunk-2Q5K7J3B-BheGxKRQ.js +1 -0
- ksadk/server/static/assets/{chunk-5VM5RSS4-DkhehZDr.js → chunk-5VM5RSS4-GJHDr9Ww.js} +1 -1
- ksadk/server/static/assets/{chunk-F27PBJKO-BdXhtPe9.js → chunk-F27PBJKO-CbAN45AV.js} +1 -1
- ksadk/server/static/assets/{chunk-G27WJ6UU-DPTpvpwi.js → chunk-G27WJ6UU-D5ngbbzF.js} +1 -1
- ksadk/server/static/assets/{chunk-JWPE2WC7-Pqoh38el.js → chunk-JWPE2WC7-Cc5IwuYC.js} +1 -1
- ksadk/server/static/assets/{chunk-LCL6LL3I-DeU00qC-.js → chunk-LCL6LL3I-CprgDDdJ.js} +1 -1
- ksadk/server/static/assets/{chunk-POPQ4Y6H-CzxScFkr.js → chunk-POPQ4Y6H-CDZhSy82.js} +1 -1
- ksadk/server/static/assets/{chunk-RHFEMEQ7-DpqMx-ux.js → chunk-RHFEMEQ7-CZchUNro.js} +1 -1
- ksadk/server/static/assets/{chunk-SVP7TREG-C6t0SypQ.js → chunk-SVP7TREG-BVruqk6T.js} +1 -1
- ksadk/server/static/assets/{chunk-XXDRQBXY-DVaeafZk.js → chunk-XXDRQBXY-4ld9SxPN.js} +1 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DSfLtNYm.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DSfLtNYm.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-JH36ORCC-Bf9D3tzJ.js → cose-bilkent-JH36ORCC-Dmyyk_Vp.js} +1 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-PFWIGtvA.js +1 -0
- ksadk/server/static/assets/{cynefinDiagram-5FMLGOSQ-B9cY3iTz.js → cynefinDiagram-5FMLGOSQ-BIyq3EJb.js} +1 -1
- ksadk/server/static/assets/{dagre-3AP2YEHR-CSwlx3CB.js → dagre-3AP2YEHR-eBw08Qdk.js} +1 -1
- ksadk/server/static/assets/{dagre-UBpgon5q.js → dagre-DfvnEf45.js} +1 -1
- ksadk/server/static/assets/{diagram-S7CK7UJ4-C9akhN9a.js → diagram-S7CK7UJ4-CUSrE3Mg.js} +1 -1
- ksadk/server/static/assets/{diagram-UQ7AKVKN-CgedhTPI.js → diagram-UQ7AKVKN-Dq5Zw2gy.js} +1 -1
- ksadk/server/static/assets/{diagram-VSXAHHWV-Cjucz5BY.js → diagram-VSXAHHWV-DyUHfNwT.js} +1 -1
- ksadk/server/static/assets/{diagram-VX7I27RA-Dd4Vleyn.js → diagram-VX7I27RA-CREmM89O.js} +1 -1
- ksadk/server/static/assets/{diagram-Z3DM3KII-CZ2jGtYW.js → diagram-Z3DM3KII-Dw9zhHUK.js} +1 -1
- ksadk/server/static/assets/{dist-Bj730Ib4.js → dist-0uJ4tdx6.js} +1 -1
- ksadk/server/static/assets/{dist-BnaTiyzN.js → dist-AEv-vXf-.js} +1 -1
- ksadk/server/static/assets/{dist-BgV_owcB.js → dist-B49GzZDb.js} +1 -1
- ksadk/server/static/assets/{dist-D_ctSS2i.js → dist-B8Myiet9.js} +1 -1
- ksadk/server/static/assets/{dist-ufY3F5p6.js → dist-BBsYarrI.js} +2 -2
- ksadk/server/static/assets/{dist-ClYUxfeK.js → dist-BQMrUwdI.js} +1 -1
- ksadk/server/static/assets/{dist-CFzsn6BG.js → dist-BX_-FENW.js} +1 -1
- ksadk/server/static/assets/{dist-B3FR1SKK.js → dist-CD4L6ymH.js} +1 -1
- ksadk/server/static/assets/{dist-Cf125P_m.js → dist-CHpW1BHj.js} +1 -1
- ksadk/server/static/assets/{dist-DVCOWtha.js → dist-CVPau3tn.js} +1 -1
- ksadk/server/static/assets/{dist-DFD6Qa6T.js → dist-C_qdxcSH.js} +1 -1
- ksadk/server/static/assets/{dist-BIr4DSRq.js → dist-Co68Apq4.js} +1 -1
- ksadk/server/static/assets/{dist-DiixqL0J.js → dist-Cp2PaOMY.js} +1 -1
- ksadk/server/static/assets/{dist-fBO2v5Kt.js → dist-CuR5Bgme.js} +1 -1
- ksadk/server/static/assets/{dist-DoVSwoDb.js → dist-DDSyLEOX.js} +1 -1
- ksadk/server/static/assets/{dist-C5_ZAZsG.js → dist-DUxO0R99.js} +1 -1
- ksadk/server/static/assets/{dist-C1NMAY5a.js → dist-QzbGrED_.js} +1 -1
- ksadk/server/static/assets/dist-bupkyEBZ.js +1 -0
- ksadk/server/static/assets/{dist-DvFK7p5S.js → dist-cxTGfdqx.js} +1 -1
- ksadk/server/static/assets/{dist-CB9iJrvg.js → dist-hL5p1til.js} +1 -1
- ksadk/server/static/assets/{dist-btbmmX5O.js → dist-lOy23y43.js} +1 -1
- ksadk/server/static/assets/{dist-QfkEHOlb.js → dist-pq-nD33R.js} +1 -1
- ksadk/server/static/assets/{ebnfDiagram-PWID7BFC-Ci8NqqZu.js → ebnfDiagram-PWID7BFC-BS5LdNoR.js} +1 -1
- ksadk/server/static/assets/{erDiagram-SSCWMZ5O-CCIOhLZG.js → erDiagram-SSCWMZ5O-Bv1QtiY-.js} +1 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-DsM4upQX.js +1 -0
- ksadk/server/static/assets/flowDiagram-A5DVABFB-D5NA16k9.js +1 -0
- ksadk/server/static/assets/{ganttDiagram-EL5Y4UJY-Cp_r9Hb6.js → ganttDiagram-EL5Y4UJY-musi-e0G.js} +1 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-DUCVz-ih.js +1 -0
- ksadk/server/static/assets/{gitGraphDiagram-WWUBYQGX-Dlhc8Wr8.js → gitGraphDiagram-WWUBYQGX-DH37EGkG.js} +1 -1
- ksadk/server/static/assets/index-CZdkAvsv.js +244 -0
- ksadk/server/static/assets/index-CvXdHgF3.css +2 -0
- ksadk/server/static/assets/info-A6RAGUB7-rw0ZNHZp.js +1 -0
- ksadk/server/static/assets/{infoDiagram-RXCK75RN-CO0rRTRA.js → infoDiagram-RXCK75RN-C1kEtv2y.js} +1 -1
- ksadk/server/static/assets/{ishikawaDiagram-5VMMS53U-CHiaedSS.js → ishikawaDiagram-5VMMS53U-BCNPyMka.js} +1 -1
- ksadk/server/static/assets/{journeyDiagram-EYS64GPL-CHcCIB09.js → journeyDiagram-EYS64GPL--cDbKnjP.js} +1 -1
- ksadk/server/static/assets/{kanban-definition-3QL26DDD-CJ_ebBZf.js → kanban-definition-3QL26DDD-R1rAVw2f.js} +1 -1
- ksadk/server/static/assets/{katex-B4weu383.js → katex-BT-X-V7U.js} +1 -1
- ksadk/server/static/assets/{linear-V-MgYHW1.js → linear-DTR631iG.js} +1 -1
- ksadk/server/static/assets/{mermaid-parser.core-CBijEX_c.js → mermaid-parser.core-DfFzJhX8.js} +2 -2
- ksadk/server/static/assets/{mindmap-definition-FBJOCRG2-Bc-pQvpp.js → mindmap-definition-FBJOCRG2-D4by_rmk.js} +1 -1
- ksadk/server/static/assets/packet-AYTQ26CC-Ca4Hvki9.js +1 -0
- ksadk/server/static/assets/{pegDiagram-XKGWAZYB-D7genGLl.js → pegDiagram-XKGWAZYB-xWXPEh0c.js} +1 -1
- ksadk/server/static/assets/pie-WAS4IAKB-hwiz6fbw.js +1 -0
- ksadk/server/static/assets/{pieDiagram-E7YTZNPT-Bxj32zwD.js → pieDiagram-E7YTZNPT-BudBDlCI.js} +1 -1
- ksadk/server/static/assets/{quadrantDiagram-AXDQQJYC-BURv2mGh.js → quadrantDiagram-AXDQQJYC-DXZ0PCJF.js} +1 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-BR1oZXLM.js +1 -0
- ksadk/server/static/assets/railroad-74A4TZTK-DfgEISfX.js +1 -0
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-CWOC3rdk.js +1 -0
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CiRvHCLY.js +1 -0
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-DSDDyJ2f.js +1 -0
- ksadk/server/static/assets/{railroadDiagram-O6MQD6OU-CCsh3avW.js → railroadDiagram-O6MQD6OU-BdAYRYB8.js} +1 -1
- ksadk/server/static/assets/{requirementDiagram-EFPCY7ZU-_FRRBKEd.js → requirementDiagram-EFPCY7ZU-CBBmaL70.js} +1 -1
- ksadk/server/static/assets/{sankeyDiagram-P5KCCOFB-C-gr2o9M.js → sankeyDiagram-P5KCCOFB-Doc3rdwp.js} +1 -1
- ksadk/server/static/assets/{sequenceDiagram-WJ2MYXX4-D97NmfKg.js → sequenceDiagram-WJ2MYXX4-0J8R8hWW.js} +1 -1
- ksadk/server/static/assets/{sizeCapture-X5ZJPWSS-DjrPC5FX.js → sizeCapture-X5ZJPWSS-CfFLlWsK.js} +1 -1
- ksadk/server/static/assets/{stateDiagram-HBIQ2CUA-DzMNg1hh.js → stateDiagram-HBIQ2CUA-jBwkjtTy.js} +1 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Cw1fPb5w.js +1 -0
- ksadk/server/static/assets/{swimlanes-XN3QIQJK-Cssf_CsU.js → swimlanes-XN3QIQJK-B0WxTQf8.js} +1 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-Cc3JMBAF.js +8 -0
- ksadk/server/static/assets/{timeline-definition-24CTP7MA-BWTHzyS1.js → timeline-definition-24CTP7MA-BfCT_75A.js} +1 -1
- ksadk/server/static/assets/treeView-Q6P3EWNA-C05SJHxo.js +1 -0
- ksadk/server/static/assets/treemap-WGGIJYW6-BqNLAhc3.js +1 -0
- ksadk/server/static/assets/{vennDiagram-4TSXK5OY-BSKgJsmR.js → vennDiagram-4TSXK5OY-9gX1VMDC.js} +1 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-DokNktqB.js +1 -0
- ksadk/server/static/assets/{wardleyDiagram-VM6X3IG4-eflHNoaZ.js → wardleyDiagram-VM6X3IG4-sEs_BP6O.js} +1 -1
- ksadk/server/static/assets/{xychartDiagram-S5SC5T6Z-eYqrQ-v4.js → xychartDiagram-S5SC5T6Z-Ll4jvUN9.js} +1 -1
- ksadk/server/static/index.html +2 -2
- ksadk/server/terminal_sessions.py +34 -2
- ksadk/sessions/__init__.py +8 -1
- ksadk/sessions/_checkpoint_resume_audit.py +44 -0
- ksadk/sessions/_in_memory_query.py +112 -0
- ksadk/sessions/_local_service_sync.py +157 -156
- ksadk/sessions/_local_state_sync.py +152 -0
- ksadk/sessions/_local_tables.py +2 -0
- ksadk/sessions/_postgres_checkpoint_read.py +323 -0
- ksadk/sessions/_postgres_checkpoint_stats.py +330 -0
- ksadk/sessions/_postgres_history_read.py +678 -0
- ksadk/sessions/_postgres_schema.py +44 -2
- ksadk/sessions/_postgres_tables.py +2 -0
- ksadk/sessions/_postgres_tool_receipts.py +169 -0
- ksadk/sessions/_resilient_read.py +630 -0
- ksadk/sessions/_tool_receipt_sync.py +119 -0
- ksadk/sessions/agent_identity.py +16 -0
- ksadk/sessions/base.py +278 -0
- ksadk/sessions/db_budget.py +332 -0
- ksadk/sessions/errors.py +12 -0
- ksadk/sessions/history_budget.py +36 -0
- ksadk/sessions/history_identity.py +27 -0
- ksadk/sessions/in_memory.py +376 -113
- ksadk/sessions/invocation_identity.py +235 -0
- ksadk/sessions/local_service.py +345 -0
- ksadk/sessions/postgres_service.py +515 -549
- ksadk/sessions/resilience.py +21 -14
- ksadk/sessions/resilient.py +611 -504
- ksadk/skills/__init__.py +26 -0
- ksadk/skills/events.py +464 -0
- ksadk/skills/loader.py +44 -2
- ksadk/skills/manifest_cache.py +263 -0
- ksadk/skills/mcp_server/__init__.py +0 -0
- ksadk/skills/mcp_server/_registry.py +33 -0
- ksadk/skills/mcp_server/_routing.py +26 -0
- ksadk/skills/mcp_server/_workspace_files.py +160 -0
- ksadk/skills/mcp_server/register.py +415 -0
- ksadk/skills/mcp_server/server.py +218 -0
- ksadk/skills/models.py +11 -0
- ksadk/skills/observability.py +132 -0
- ksadk/skills/package_store.py +75 -2
- ksadk/skills/runtime/agent.py +38 -5
- ksadk/skills/runtime/artifacts.py +87 -0
- ksadk/skills/runtime/backends/e2b.py +400 -56
- ksadk/skills/runtime/backends/local.py +621 -119
- ksadk/skills/runtime/base.py +78 -7
- ksadk/skills/runtime/executor.py +266 -1
- ksadk/skills/runtime/loader.py +108 -3
- ksadk/skills/runtime/request.py +18 -0
- ksadk/skills/service_client.py +6 -1
- ksadk/skills/tool_defs.py +108 -3
- ksadk/studio/a2a_bindings.py +407 -0
- ksadk/studio/a2a_orchestration.py +178 -0
- ksadk/studio/active_run_output.py +92 -0
- ksadk/studio/activity_records.py +542 -0
- ksadk/studio/agent_configuration.py +173 -0
- ksadk/studio/api.py +784 -419
- ksadk/studio/api_a2a_routes.py +93 -0
- ksadk/studio/api_catalog_routes.py +13 -0
- ksadk/studio/api_cloud_chat_routes.py +382 -0
- ksadk/studio/api_contracts.py +31 -2
- ksadk/studio/api_plugin_routes.py +39 -12
- ksadk/studio/api_resource_connections.py +79 -41
- ksadk/studio/attachment_store.py +14 -2
- ksadk/studio/authoring.py +12 -6
- ksadk/studio/authoring_coordinator.py +4 -2
- ksadk/studio/build_resolution.py +117 -0
- ksadk/studio/build_singleflight.py +37 -0
- ksadk/studio/builder.py +32 -2
- ksadk/studio/capabilities.py +31 -9
- ksadk/studio/channel_connections.py +333 -0
- ksadk/studio/cloud.py +113 -387
- ksadk/studio/cloud_gateways.py +424 -0
- ksadk/studio/cloud_shared_web.py +82 -2
- ksadk/studio/codex_agent_service.py +19 -2
- ksadk/studio/codex_builder.py +1 -1
- ksadk/studio/codex_manifest.py +5 -1
- ksadk/studio/codex_provider_build.py +65 -0
- ksadk/studio/codex_run.py +6 -1
- ksadk/studio/compiler.py +112 -6
- ksadk/studio/configuration.py +182 -0
- ksadk/studio/contract_base.py +19 -0
- ksadk/studio/contracts.py +260 -202
- ksadk/studio/dsh_application.py +183 -27
- ksadk/studio/dsh_capability_service.py +302 -189
- ksadk/studio/dsh_lifecycle.py +58 -0
- ksadk/studio/dsh_mcp_transport.py +191 -0
- ksadk/studio/dsh_provider_registration.py +55 -16
- ksadk/studio/entry.py +53 -0
- ksadk/studio/event_store.py +53 -5
- ksadk/studio/execution_host.py +598 -0
- ksadk/studio/framework_run.py +50 -10
- ksadk/studio/hosted_kernel.py +1 -1
- ksadk/studio/interaction_submission.py +265 -0
- ksadk/studio/kernel_registry.py +429 -0
- ksadk/studio/kernel_sqlite_migration.py +181 -0
- ksadk/studio/lifecycle_status.py +43 -0
- ksadk/studio/model_buffered_wire.py +227 -0
- ksadk/studio/model_chat_tools.py +143 -0
- ksadk/studio/model_client.py +1939 -345
- ksadk/studio/model_content_stream.py +129 -0
- ksadk/studio/model_credentials.py +196 -0
- ksadk/studio/model_profile_service.py +89 -40
- ksadk/studio/model_request_projection.py +284 -0
- ksadk/studio/model_responses_content.py +296 -0
- ksadk/studio/model_usage.py +109 -0
- ksadk/studio/model_wire_failure.py +110 -0
- ksadk/studio/model_wire_identity.py +138 -0
- ksadk/studio/model_wire_snapshot.py +45 -0
- ksadk/studio/model_wire_tools.py +283 -0
- ksadk/studio/native_acceptance.py +68 -0
- ksadk/studio/native_approval.py +111 -0
- ksadk/studio/native_browser_port.py +861 -0
- ksadk/studio/native_child_mcp.py +87 -0
- ksadk/studio/native_child_publication.py +68 -0
- ksadk/studio/native_child_skills.py +72 -0
- ksadk/studio/native_child_workspace.py +176 -0
- ksadk/studio/native_command_policy.py +53 -0
- ksadk/studio/native_context_port.py +326 -0
- ksadk/studio/native_context_registration.py +54 -0
- ksadk/studio/native_document_input.py +88 -0
- ksadk/studio/native_documents.py +172 -0
- ksadk/studio/native_final_shape.py +852 -0
- ksadk/studio/native_gateway_stream.py +69 -0
- ksadk/studio/native_hook_port.py +145 -0
- ksadk/studio/native_hook_registration.py +70 -0
- ksadk/studio/native_inventory_disclosure.py +223 -0
- ksadk/studio/native_kernel_admission.py +84 -0
- ksadk/studio/native_language_diagnostics.py +320 -0
- ksadk/studio/native_mcp_disclosure.py +198 -0
- ksadk/studio/native_mcp_tool_port.py +219 -0
- ksadk/studio/native_memory_acceptance.py +362 -0
- ksadk/studio/native_memory_context.py +266 -0
- ksadk/studio/native_memory_flush.py +174 -0
- ksadk/studio/native_memory_sources.py +80 -0
- ksadk/studio/native_memory_tool_port.py +360 -0
- ksadk/studio/native_memory_turn.py +183 -0
- ksadk/studio/native_model_port.py +765 -0
- ksadk/studio/native_model_recovery.py +126 -0
- ksadk/studio/native_options.py +75 -0
- ksadk/studio/native_output_fields.py +58 -0
- ksadk/studio/native_planning.py +156 -0
- ksadk/studio/native_product.py +988 -0
- ksadk/studio/native_read_budget.py +426 -0
- ksadk/studio/native_recovery.py +171 -0
- ksadk/studio/native_scope.py +35 -0
- ksadk/studio/native_session_context_port.py +141 -0
- ksadk/studio/native_session_engine.py +14 -0
- ksadk/studio/native_skill_source.py +74 -0
- ksadk/studio/native_subagent_port.py +700 -0
- ksadk/studio/native_terminal_recovery.py +95 -0
- ksadk/studio/native_test_action.py +610 -0
- ksadk/studio/native_tool_port.py +477 -0
- ksadk/studio/native_user_input.py +60 -0
- ksadk/studio/native_verification_presentation.py +65 -0
- ksadk/studio/native_workspace_diagnostics.py +183 -0
- ksadk/studio/native_workspace_port.py +43 -0
- ksadk/studio/operations.py +34 -9
- ksadk/studio/plugin_composition.py +39 -12
- ksadk/studio/plugin_kernel_adapter.py +89 -0
- ksadk/studio/plugin_lifecycle.py +80 -0
- ksadk/studio/plugin_native_activation.py +163 -0
- ksadk/studio/plugin_runtime.py +832 -99
- ksadk/studio/plugin_runtime_admission.py +57 -0
- ksadk/studio/presentation.py +92 -0
- ksadk/studio/provider_recovery.py +59 -0
- ksadk/studio/public_output_store.py +69 -0
- ksadk/studio/recovery_page.py +70 -0
- ksadk/studio/resource_authority.py +69 -34
- ksadk/studio/resource_catalog.py +14 -12
- ksadk/studio/run_activity.py +848 -0
- ksadk/studio/run_controls.py +185 -0
- ksadk/studio/run_documents.py +127 -0
- ksadk/studio/run_service.py +1220 -335
- ksadk/studio/run_submission_receipts.py +68 -0
- ksadk/studio/runtime_catalog.py +73 -11
- ksadk/studio/runtime_prewarm.py +22 -0
- ksadk/studio/runtime_source.py +1 -1
- ksadk/studio/scheduler_assistant.py +4 -1
- ksadk/studio/scheduler_runtime.py +32 -289
- ksadk/studio/service.py +615 -246
- ksadk/studio/service_settings.py +229 -0
- ksadk/studio/shared_web.py +518 -181
- ksadk/studio/shared_web_response_events.py +180 -0
- ksadk/studio/shared_web_run_state.py +133 -0
- ksadk/studio/skill_discovery.py +305 -3
- ksadk/studio/static/assets/ChannelsPage-xX5HlMId.js +8 -0
- ksadk/studio/static/assets/CodeBlock-DMIf4h33-CkufcPYo.js +44 -0
- ksadk/studio/static/assets/ExecutionTree-v3HexvPo-Bk8wzGSy.js +1 -0
- ksadk/studio/static/assets/MathMessageMarkdown-BesSeCYl-DYG1Wzbx.js +8 -0
- ksadk/studio/static/assets/MermaidBlock-H_0qzQDf-BdXtxug_.js +11 -0
- ksadk/studio/static/assets/MessageMarkdown-CwMTvgFj-BeyLyQHu.js +59 -0
- ksadk/studio/static/assets/PrismRenderer-5pK6tUdb.js +3 -0
- ksadk/studio/static/assets/TeamsPage-CCaaGaVp.js +3 -0
- ksadk/studio/static/assets/abnfDiagram-VCTEODGH-Bnb1O3tA.js +1 -0
- ksadk/studio/static/assets/architecture-7GRP2DOG-BMOPAkUC.js +1 -0
- ksadk/studio/static/assets/architectureDiagram-5GKGNRK7-5Zn1gqJv.js +36 -0
- ksadk/studio/static/assets/{blockDiagram-I7D4REHJ-CFmPl1de.js → blockDiagram-I7D4REHJ-CLB4L11u.js} +6 -6
- ksadk/studio/static/assets/{c4Diagram-7LVT6UL2-BRrGu8qt.js → c4Diagram-7LVT6UL2-BOma_Z_F.js} +7 -7
- ksadk/studio/static/assets/channel-r8itPEik.js +1 -0
- ksadk/studio/static/assets/chunk-2E4U76K2-BFf_huql.js +2 -0
- ksadk/studio/static/assets/chunk-2ZTRR5NV-C2qZJila.js +2 -0
- ksadk/studio/static/assets/chunk-3Z5EZCMW-DMniOlPd.js +1 -0
- ksadk/studio/static/assets/{chunk-4HAMMTFA-D220vUtq.js → chunk-4HAMMTFA-DVtDP4rm.js} +7 -7
- ksadk/studio/static/assets/chunk-5V3GS4D5-i-ZDOEnP.js +1 -0
- ksadk/studio/static/assets/chunk-6AZGARVD-BB6FqMl-.js +1 -0
- ksadk/studio/static/assets/chunk-6EIED4P4-DdUJkP0f.js +1 -0
- ksadk/studio/static/assets/chunk-6K3QC6MW-CqVsVn-y.js +1 -0
- ksadk/studio/static/assets/chunk-6TQVIW2G-DKlLbNIP.js +1 -0
- ksadk/studio/static/assets/chunk-747NJXEK-BFkZPlab.js +2 -0
- ksadk/studio/static/assets/chunk-75Z2AOVW-BZNhM4vB.js +2 -0
- ksadk/studio/static/assets/chunk-CLGD4ZFX-D-GTtyKs.js +1 -0
- ksadk/studio/static/assets/{chunk-DU6HZSFF-C4DtVpCu.js → chunk-DU6HZSFF-CpEZCUgg.js} +1 -1
- ksadk/studio/static/assets/chunk-F27PBJKO-D7pvKf0C.js +1 -0
- ksadk/studio/static/assets/{chunk-GMAD6QVW-DiQA-u2N.js → chunk-GMAD6QVW-DE_8H717.js} +6 -6
- ksadk/studio/static/assets/chunk-GVQU2GXP-BfEB0lNv.js +1 -0
- ksadk/studio/static/assets/chunk-I5DQTOEV-Hm2LfiYI.js +1 -0
- ksadk/studio/static/assets/chunk-ICYGCRZG-749o-pGJ.js +1 -0
- ksadk/studio/static/assets/chunk-IH6LHLGP-CC6I9F3i.js +1 -0
- ksadk/studio/static/assets/{chunk-IMKFNOWR-BSlbjT_b.js → chunk-IMKFNOWR-D38axYOR.js} +5 -5
- ksadk/studio/static/assets/chunk-KI3K4JFJ-Rma-0k_M.js +1 -0
- ksadk/studio/static/assets/chunk-L3NEJ4N5-Dq5xn7aL.js +1 -0
- ksadk/studio/static/assets/chunk-LNGE3PJU-DWpGwHrW.js +34 -0
- ksadk/studio/static/assets/{chunk-OSK3NFVY-M2m6G3j4.js → chunk-OSK3NFVY-DiCQjx9b.js} +5 -5
- ksadk/studio/static/assets/chunk-OUJLGHUK-D0j2JRSg.js +2 -0
- ksadk/studio/static/assets/{chunk-P2QGCYS3-DezaQxiK.js → chunk-P2QGCYS3-VdhKmfYq.js} +1 -1
- ksadk/studio/static/assets/chunk-POPQ4Y6H-C1_rzO5M.js +1 -0
- ksadk/studio/static/assets/chunk-PWAF6VOD-B45HvflI.js +1 -0
- ksadk/studio/static/assets/{chunk-SHT3W25Y-DAyIVp5H.js → chunk-SHT3W25Y-DsCFnRVE.js} +9 -9
- ksadk/studio/static/assets/{chunk-SVP7TREG-DulomOrS.js → chunk-SVP7TREG-DljApgRX.js} +1 -1
- ksadk/studio/static/assets/{chunk-TICWLB2K-bHJYoflj.js → chunk-TICWLB2K-DWqRtyqa.js} +6 -6
- ksadk/studio/static/assets/chunk-TLUHSLCS-DUeGgnD5.js +2 -0
- ksadk/studio/static/assets/chunk-UY3FDG6J-CnmaAkG5.js +1 -0
- ksadk/studio/static/assets/chunk-XHIXRSVI-BFQ6B8BE.js +1 -0
- ksadk/studio/static/assets/chunk-XXDRQBXY-DqAYeljN.js +1 -0
- ksadk/studio/static/assets/classDiagram-ZZMXUADV-DjeMNJmu.js +1 -0
- ksadk/studio/static/assets/classDiagram-v2-VYDZK3BY-DjeMNJmu.js +1 -0
- ksadk/studio/static/assets/clsx-DB0hHKMi.js +1 -0
- ksadk/studio/static/assets/cose-bilkent-JH36ORCC-om8AY0Mc.js +1 -0
- ksadk/studio/static/assets/createLucideIcon-DR0LGTP5.js +1 -0
- ksadk/studio/static/assets/cynefin-OW5HDTMX-7tP7QfM3.js +1 -0
- ksadk/studio/static/assets/cynefinDiagram-5FMLGOSQ-6BrmK52S.js +62 -0
- ksadk/studio/static/assets/dagre-GXQ25YYZ-buZBRlwz.js +4 -0
- ksadk/studio/static/assets/{diagram-S7CK7UJ4-0BZ98mya.js → diagram-S7CK7UJ4-C6aH78c4.js} +3 -3
- ksadk/studio/static/assets/diagram-UQ7AKVKN-DY_tQ6C_.js +41 -0
- ksadk/studio/static/assets/diagram-VSXAHHWV-DX9p5cQT.js +3 -0
- ksadk/studio/static/assets/diagram-VX7I27RA-DB2WSH8X.js +24 -0
- ksadk/studio/static/assets/diagram-Z3DM3KII-Ce1BJwHE.js +24 -0
- ksadk/studio/static/assets/ebnfDiagram-PWID7BFC-Daukxwqf.js +1 -0
- ksadk/studio/static/assets/{erDiagram-RLTQ6QDP-DLGry2Ap.js → erDiagram-RLTQ6QDP-CGthTMmJ.js} +6 -6
- ksadk/studio/static/assets/eventmodeling-NTZA5JFV-BR2FzK4R.js +1 -0
- ksadk/studio/static/assets/flowDiagram-HODETNUW-CZ1tEenp.js +1 -0
- ksadk/studio/static/assets/ganttDiagram-EL5Y4UJY-BfoAZW9X.js +292 -0
- ksadk/studio/static/assets/gitGraph-4MIJSDKK-DYlXv_yJ.js +1 -0
- ksadk/studio/static/assets/gitGraphDiagram-WWUBYQGX-S985OIJF.js +106 -0
- ksadk/studio/static/assets/iconfont-4HN3C9Pg.woff2 +0 -0
- ksadk/studio/static/assets/index-C7DNDik2.css +2 -0
- ksadk/studio/static/assets/index-Cy68gTlH.js +265 -0
- ksadk/studio/static/assets/index.dom-BQenBtFm.js +1 -0
- ksadk/studio/static/assets/info-A6RAGUB7-BlU-8_xu.js +1 -0
- ksadk/studio/static/assets/infoDiagram-27XIBGKW-CO3W8tFn.js +2 -0
- ksadk/studio/static/assets/{ishikawaDiagram-5VMMS53U-CljI2wyf.js → ishikawaDiagram-5VMMS53U-BUGEl8cO.js} +2 -2
- ksadk/studio/static/assets/{journeyDiagram-3NMN7TZE-D50Fo2sL.js → journeyDiagram-3NMN7TZE-Ch2ZYxvr.js} +6 -6
- ksadk/studio/static/assets/{kanban-definition-UXKFOSKX-DimfOTam.js → kanban-definition-UXKFOSKX-Da-Fp4vC.js} +3 -3
- ksadk/studio/static/assets/kingsoft-cloud-BOcLiQ3e.ico +0 -0
- ksadk/studio/static/assets/{line-CX5BOOUP.js → line-BDaeq300.js} +1 -1
- ksadk/studio/static/assets/linear-DmucvK78.js +1 -0
- ksadk/studio/static/assets/mermaid-parser.core-Cj5mYdBi.js +4 -0
- ksadk/studio/static/assets/{mindmap-definition-YA3MSWOX-Bizzqy5R.js → mindmap-definition-YA3MSWOX-CvlsVQ38.js} +1 -1
- ksadk/studio/static/assets/packet-AYTQ26CC-BSJEH9Lb.js +1 -0
- ksadk/studio/static/assets/pegDiagram-XKGWAZYB-BuHuNgT5.js +1 -0
- ksadk/studio/static/assets/pie-WAS4IAKB-qxv01Y8W.js +1 -0
- ksadk/studio/static/assets/{pieDiagram-E7YTZNPT-B9mrFSDF.js → pieDiagram-E7YTZNPT-DlrWiSOv.js} +1 -1
- ksadk/studio/static/assets/preload-helper-CO68xz6u.js +1 -0
- ksadk/studio/static/assets/presentation-yYw7xK60-BmcZriri.js +1 -0
- ksadk/studio/static/assets/{quadrantDiagram-AXDQQJYC-NzUfCbMR.js → quadrantDiagram-AXDQQJYC-BA3hpUZM.js} +6 -6
- ksadk/studio/static/assets/radar-RG4KPBEZ-B6h6pWOs.js +1 -0
- ksadk/studio/static/assets/railroad-74A4TZTK-CGtTWdGc.js +1 -0
- ksadk/studio/static/assets/railroad-abnf-HS5TGJTU-Cq7y22IA.js +1 -0
- ksadk/studio/static/assets/railroad-ebnf-LZEXJU2U-V0aQVv9m.js +1 -0
- ksadk/studio/static/assets/railroad-peg-WCYAUIDC-BQiIsX_p.js +1 -0
- ksadk/studio/static/assets/railroadDiagram-O6MQD6OU-BxpAazym.js +1 -0
- ksadk/studio/static/assets/{requirementDiagram-BXWQKSXE-BF3d103U.js → requirementDiagram-BXWQKSXE-E-Ge0FcV.js} +1 -1
- ksadk/studio/static/assets/sankeyDiagram-P5KCCOFB-CA6YKhQ3.js +40 -0
- ksadk/studio/static/assets/{sequenceDiagram-WJ2MYXX4-Dh4wZtUm.js → sequenceDiagram-WJ2MYXX4-CcElXGg4.js} +9 -9
- ksadk/studio/static/assets/src-B6xuSHsQ.js +1 -0
- ksadk/studio/static/assets/stateDiagram-D77RDMKH-DdXZOFqY.js +1 -0
- ksadk/studio/static/assets/stateDiagram-v2-MP3YSRHH-CJbOM-QK.js +1 -0
- ksadk/studio/static/assets/swimlanes-42K2YHIH-NtgEEHLY.js +1 -0
- ksadk/studio/static/assets/swimlanesDiagram-VR7AAH4N-D-AVlW8B.js +8 -0
- ksadk/studio/static/assets/{timeline-definition-24CTP7MA-DxmSSjRB.js → timeline-definition-24CTP7MA-CIuYhNy3.js} +7 -7
- ksadk/studio/static/assets/treeView-Q6P3EWNA-BTTYcvrF.js +1 -0
- ksadk/studio/static/assets/treemap-WGGIJYW6-Cg7tyfH8.js +1 -0
- ksadk/studio/static/assets/vennDiagram-4TSXK5OY-7HbApbrv.js +34 -0
- ksadk/studio/static/assets/wardley-WFR3VGLG-C6N1rULY.js +1 -0
- ksadk/studio/static/assets/{wardleyDiagram-VM6X3IG4-Ba1AOWoe.js → wardleyDiagram-VM6X3IG4-CMJiaedy.js} +1 -1
- ksadk/studio/static/assets/{xychartDiagram-S5SC5T6Z-Cr5pt5Y-.js → xychartDiagram-S5SC5T6Z-BdgtMvW2.js} +6 -6
- ksadk/studio/static/index.html +8 -2
- ksadk/studio/teams_catalog.py +166 -0
- ksadk/studio/teams_installation.py +217 -0
- ksadk/studio/teams_node.py +549 -0
- ksadk/studio/teams_node_factory.py +558 -0
- ksadk/studio/teams_node_runner.py +72 -0
- ksadk/studio/teams_node_v1.py +935 -0
- ksadk/studio/teams_remote.py +496 -0
- ksadk/studio/templates.py +41 -19
- ksadk/studio/validator.py +13 -0
- ksadk/studio/workspace.py +19 -4
- ksadk/studio/workspace_plugins.py +138 -0
- ksadk/studio/workspace_registry.py +286 -0
- ksadk/tools/a2a_policy.py +5 -0
- ksadk/tools/artifact_observation.py +53 -0
- ksadk/tools/captured_source_artifact.py +68 -0
- ksadk/tools/schema.py +34 -0
- ksadk/toolsets/__init__.py +93 -88
- ksadk/toolsets/a2a.py +89 -89
- ksadk/toolsets/sandbox.py +377 -6
- ksadk/toolsets/skill_management.py +315 -0
- ksadk/toolsets/skills.py +446 -378
- ksadk/toolsets/tool_selection.py +94 -0
- ksadk/toolsets/workspace.py +344 -326
- ksadk/toolsets/workspace_editing.py +291 -0
- ksadk/toolsets/workspace_identity.py +15 -0
- ksadk/toolsets/workspace_model_observation.py +104 -0
- ksadk/toolsets/workspace_mutation.py +75 -0
- ksadk/toolsets/workspace_read_budget.py +216 -0
- ksadk/toolsets/workspace_search.py +192 -0
- ksadk/toolsets/workspace_search_process.py +129 -0
- ksadk/toolsets/workspace_state.py +6 -0
- ksadk/version.py +1 -1
- ksadk_runtime_common/http_headers.py +18 -0
- ksadk_runtime_common/memory_backend/providers/lancedb.py +56 -2
- ksadk_runtime_common/schemas/memory_backend_manifest.schema.json +148 -148
- ksadk_runtime_common/workspace_files/router.py +28 -14
- agentengine_sdk_python-0.8.4.dist-info/RECORD +0 -1070
- ksadk/server/static/assets/MathMessageMarkdown-DbdW5A4_.js +0 -8
- ksadk/server/static/assets/architecture-7GRP2DOG-BW5UtSnx.js +0 -1
- ksadk/server/static/assets/channel-CF5Up3hQ.js +0 -1
- ksadk/server/static/assets/chunk-2Q5K7J3B-KkXX47WI.js +0 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-Cz81acRQ.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-Cz81acRQ.js +0 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-DVWs8a2t.js +0 -1
- ksadk/server/static/assets/dist-B2_CVgKv.js +0 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-CQqR2hg3.js +0 -1
- ksadk/server/static/assets/flowDiagram-A5DVABFB-DDRRbGPm.js +0 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-fgWEf7UD.js +0 -1
- ksadk/server/static/assets/index-DcTML1Up.css +0 -2
- ksadk/server/static/assets/index-Dh2XHqPK.js +0 -244
- ksadk/server/static/assets/info-A6RAGUB7-BUecLTdt.js +0 -1
- ksadk/server/static/assets/packet-AYTQ26CC-BeW-btFv.js +0 -1
- ksadk/server/static/assets/pie-WAS4IAKB-X0xh4SaT.js +0 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-DzRMSqjd.js +0 -1
- ksadk/server/static/assets/railroad-74A4TZTK-Cc44icX-.js +0 -1
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-D6S4BdV-.js +0 -1
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-vD3aVE2o.js +0 -1
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-CYbW_b4T.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-BIcjKFhF.js +0 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-tq3K3Ybl.js +0 -8
- ksadk/server/static/assets/treeView-Q6P3EWNA-DBXt3GdU.js +0 -1
- ksadk/server/static/assets/treemap-WGGIJYW6-DrCy4E_l.js +0 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-CefhOliM.js +0 -1
- ksadk/studio/static/assets/CodeBlock-DCUUY0PL-BLjA7kbS.js +0 -41
- ksadk/studio/static/assets/MathMessageMarkdown-CBcDrAw--CUYIXwgI.js +0 -8
- ksadk/studio/static/assets/MermaidBlock-DBFTztfQ-BTYKWEbD.js +0 -44
- ksadk/studio/static/assets/PrismRenderer-wiXRHURw.js +0 -3
- ksadk/studio/static/assets/abnfDiagram-VCTEODGH-CLETGjKq.js +0 -1
- ksadk/studio/static/assets/architecture-7GRP2DOG-hXMiO_AU.js +0 -1
- ksadk/studio/static/assets/architectureDiagram-5GKGNRK7-B5EQysk6.js +0 -36
- ksadk/studio/static/assets/channel-BqO-gtEw.js +0 -1
- ksadk/studio/static/assets/chunk-75Z2AOVW-C8lLv_qc.js +0 -2
- ksadk/studio/static/assets/chunk-F27PBJKO-Cpw14SNG.js +0 -1
- ksadk/studio/static/assets/chunk-GVQU2GXP-DUdNBUCi.js +0 -1
- ksadk/studio/static/assets/chunk-L3NEJ4N5-Db8Ab22W.js +0 -1
- ksadk/studio/static/assets/chunk-POPQ4Y6H-DOpufJ3t.js +0 -1
- ksadk/studio/static/assets/chunk-PWAF6VOD-CfLb1gSc.js +0 -1
- ksadk/studio/static/assets/chunk-XXDRQBXY-7PcdR2B1.js +0 -1
- ksadk/studio/static/assets/classDiagram-ZZMXUADV-D_bW8JjA.js +0 -1
- ksadk/studio/static/assets/classDiagram-v2-VYDZK3BY-D_bW8JjA.js +0 -1
- ksadk/studio/static/assets/cose-bilkent-JH36ORCC-snL88wkX.js +0 -1
- ksadk/studio/static/assets/cynefin-OW5HDTMX-Bd1YhRo1.js +0 -1
- ksadk/studio/static/assets/cynefinDiagram-5FMLGOSQ-BBrIG_mI.js +0 -62
- ksadk/studio/static/assets/dagre-GXQ25YYZ-DtF1nGdY.js +0 -4
- ksadk/studio/static/assets/diagram-UQ7AKVKN-6mLKEo6L.js +0 -41
- ksadk/studio/static/assets/diagram-VSXAHHWV-CJBIaiZ2.js +0 -3
- ksadk/studio/static/assets/diagram-VX7I27RA-BohLEE1C.js +0 -24
- ksadk/studio/static/assets/diagram-Z3DM3KII-D8KIGonG.js +0 -24
- ksadk/studio/static/assets/ebnfDiagram-PWID7BFC-C99HU61t.js +0 -1
- ksadk/studio/static/assets/eventmodeling-NTZA5JFV-B1_5Ac8j.js +0 -1
- ksadk/studio/static/assets/flowDiagram-HODETNUW-DD5hmicn.js +0 -1
- ksadk/studio/static/assets/ganttDiagram-EL5Y4UJY-BPJrVLSG.js +0 -292
- ksadk/studio/static/assets/gitGraph-4MIJSDKK-Cy_ZQBGi.js +0 -1
- ksadk/studio/static/assets/gitGraphDiagram-WWUBYQGX-CZCUz4MT.js +0 -106
- ksadk/studio/static/assets/index-CeHL9ARV.css +0 -2
- ksadk/studio/static/assets/index-D9QEcVpL.js +0 -320
- ksadk/studio/static/assets/info-A6RAGUB7-DBzDQB_I.js +0 -1
- ksadk/studio/static/assets/infoDiagram-27XIBGKW-B-sq07Hi.js +0 -2
- ksadk/studio/static/assets/linear-BCxN9JLv.js +0 -1
- ksadk/studio/static/assets/mermaid-parser.core-BdCz8fkS.js +0 -7
- ksadk/studio/static/assets/packet-AYTQ26CC-gPln-_kG.js +0 -1
- ksadk/studio/static/assets/pegDiagram-XKGWAZYB-Dy3fB-gW.js +0 -1
- ksadk/studio/static/assets/pie-WAS4IAKB-qZdHMr7B.js +0 -1
- ksadk/studio/static/assets/radar-RG4KPBEZ-BZlnaea9.js +0 -1
- ksadk/studio/static/assets/railroad-74A4TZTK-Ce3__H9c.js +0 -1
- ksadk/studio/static/assets/railroad-abnf-HS5TGJTU-DqQn7EzD.js +0 -1
- ksadk/studio/static/assets/railroad-ebnf-LZEXJU2U-B55kCA8F.js +0 -1
- ksadk/studio/static/assets/railroad-peg-WCYAUIDC-DfQnvkHd.js +0 -1
- ksadk/studio/static/assets/railroadDiagram-O6MQD6OU-DnhMjZCk.js +0 -1
- ksadk/studio/static/assets/sankeyDiagram-P5KCCOFB-Bo-JTwt0.js +0 -40
- ksadk/studio/static/assets/src-SFn9St9H.js +0 -1
- ksadk/studio/static/assets/stateDiagram-D77RDMKH-DH774G6d.js +0 -1
- ksadk/studio/static/assets/stateDiagram-v2-MP3YSRHH-DZvVWPBo.js +0 -1
- ksadk/studio/static/assets/swimlanes-42K2YHIH-Bl13OvTX.js +0 -1
- ksadk/studio/static/assets/swimlanesDiagram-VR7AAH4N-BnFOTALJ.js +0 -8
- ksadk/studio/static/assets/treeView-Q6P3EWNA-D5Nn9Swz.js +0 -1
- ksadk/studio/static/assets/treemap-WGGIJYW6-CgHgnQhE.js +0 -1
- ksadk/studio/static/assets/vennDiagram-4TSXK5OY-B9QEXcJq.js +0 -34
- ksadk/studio/static/assets/wardley-WFR3VGLG-DXrK2RRY.js +0 -1
- {agentengine_sdk_python-0.8.4.dist-info → agentengine_sdk_python-0.8.6.dist-info}/WHEEL +0 -0
- {agentengine_sdk_python-0.8.4.dist-info → agentengine_sdk_python-0.8.6.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.4.dist-info → agentengine_sdk_python-0.8.6.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.4.dist-info → agentengine_sdk_python-0.8.6.dist-info}/top_level.txt +0 -0
- /ksadk/studio/static/assets/{MathMessageMarkdown-CBcDrAw--BEOyPC3w.css → MathMessageMarkdown-BesSeCYl-BEOyPC3w.css} +0 -0
|
@@ -5,19 +5,25 @@ from __future__ import annotations
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import json
|
|
7
7
|
import logging
|
|
8
|
+
import os
|
|
8
9
|
import time
|
|
9
10
|
from collections.abc import AsyncIterator
|
|
11
|
+
from contextlib import aclosing, asynccontextmanager, nullcontext
|
|
10
12
|
from contextvars import ContextVar
|
|
13
|
+
from functools import wraps
|
|
11
14
|
from typing import Any, Optional
|
|
12
15
|
from urllib.parse import urlsplit, urlunsplit
|
|
13
16
|
|
|
14
17
|
from ksadk.ids import new_session_id
|
|
18
|
+
from ksadk.sessions._checkpoint_resume_audit import CheckpointResumeAudit
|
|
15
19
|
from ksadk.sessions._postgres_schema import _PostgresSchemaMixin
|
|
16
20
|
from ksadk.sessions._postgres_tables import (
|
|
17
21
|
KSADK_PG_EVENTS_TABLE,
|
|
18
22
|
KSADK_PG_SESSIONS_TABLE,
|
|
19
23
|
KSADK_PG_STATES_TABLE,
|
|
24
|
+
pg_tool_receipts_table,
|
|
20
25
|
)
|
|
26
|
+
from ksadk.sessions._postgres_tool_receipts import _PostgresToolReceiptMixin
|
|
21
27
|
from ksadk.sessions.base import (
|
|
22
28
|
CANONICAL_EVENT_STORAGE_CAPABILITIES,
|
|
23
29
|
BaseSessionService,
|
|
@@ -26,16 +32,218 @@ from ksadk.sessions.base import (
|
|
|
26
32
|
SessionEvent,
|
|
27
33
|
SessionEventQuery,
|
|
28
34
|
SessionState,
|
|
35
|
+
checkpoint_creation_identity,
|
|
36
|
+
checkpoint_resume_identity,
|
|
29
37
|
generate_id,
|
|
30
38
|
)
|
|
31
|
-
from ksadk.sessions.
|
|
39
|
+
from ksadk.sessions.db_budget import (
|
|
40
|
+
DatabaseBudget,
|
|
41
|
+
_cleanup_deadline,
|
|
42
|
+
bounded_cleanup,
|
|
43
|
+
bounded_driver_call,
|
|
44
|
+
release_pool_lease,
|
|
45
|
+
session_db_budget,
|
|
46
|
+
)
|
|
47
|
+
from ksadk.sessions.errors import HistoryProjectionBudgetExceeded, SessionBackendUnavailable
|
|
48
|
+
from ksadk.sessions.history_budget import CURRENT_HISTORY_READ_BUDGET
|
|
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
|
|
32
55
|
|
|
33
56
|
logger = logging.getLogger(__name__)
|
|
34
57
|
|
|
35
58
|
|
|
36
|
-
|
|
59
|
+
def _write_deadline(method):
|
|
60
|
+
"""Include cold schema/pool initialization in the write operation cap."""
|
|
61
|
+
@wraps(method)
|
|
62
|
+
async def bounded(self, *args, **kwargs):
|
|
63
|
+
async with asyncio.timeout(self.db_budget.write_operation_seconds):
|
|
64
|
+
return await method(self, *args, **kwargs)
|
|
65
|
+
return bounded
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class _TimedConnection:
|
|
69
|
+
"""Apply the phase's command budget to every asyncpg statement."""
|
|
70
|
+
|
|
71
|
+
def __init__(self, connection: Any, sql_seconds: float, cleanup_seconds: float = 1.0, replay_seconds: float = 30.0, replay_sql_seconds: float | None = None) -> None:
|
|
72
|
+
self._connection = connection
|
|
73
|
+
self._sql_seconds = sql_seconds
|
|
74
|
+
self._cleanup_seconds = cleanup_seconds
|
|
75
|
+
self._replay_seconds = replay_seconds
|
|
76
|
+
self._replay_sql_seconds = sql_seconds if replay_sql_seconds is None else replay_sql_seconds
|
|
77
|
+
|
|
78
|
+
def __getattr__(self, name: str) -> Any:
|
|
79
|
+
return getattr(self._connection, name)
|
|
80
|
+
|
|
81
|
+
async def execute(self, query: str, *args: Any, **kwargs: Any) -> Any:
|
|
82
|
+
seconds = kwargs.pop("timeout", self._sql_seconds)
|
|
83
|
+
return await bounded_driver_call(
|
|
84
|
+
self._connection.execute(query, *args, timeout=seconds, **kwargs),
|
|
85
|
+
self._connection, seconds, self._cleanup_seconds,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
async def fetch(self, query: str, *args: Any, **kwargs: Any) -> Any:
|
|
89
|
+
seconds = kwargs.pop("timeout", self._sql_seconds)
|
|
90
|
+
return await bounded_driver_call(
|
|
91
|
+
self._connection.fetch(query, *args, timeout=seconds, **kwargs),
|
|
92
|
+
self._connection, seconds, self._cleanup_seconds,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
async def fetch_replay(self, query: str, *args: Any, batch_size: int = 32) -> Any:
|
|
96
|
+
"""Fetch complete replay through a fixed cursor with bounded commands.
|
|
97
|
+
|
|
98
|
+
Full context can exceed a history page's one-second SQL budget in
|
|
99
|
+
aggregate. Small cursor batches have a dedicated command budget; the
|
|
100
|
+
whole replay has a separate deadline and cancellation rolls back.
|
|
101
|
+
"""
|
|
102
|
+
if not callable(getattr(self._connection, "cursor", None)):
|
|
103
|
+
return await self.fetch(query, *args)
|
|
104
|
+
rows = []
|
|
105
|
+
async with asyncio.timeout(self._replay_seconds):
|
|
106
|
+
async with self.transaction():
|
|
107
|
+
async def bind_cursor():
|
|
108
|
+
return await self._connection.cursor(query, *args, timeout=self._replay_sql_seconds)
|
|
109
|
+
cursor = await bounded_driver_call(
|
|
110
|
+
bind_cursor(),
|
|
111
|
+
self._connection, self._replay_sql_seconds, self._cleanup_seconds,
|
|
112
|
+
)
|
|
113
|
+
while True:
|
|
114
|
+
batch = await bounded_driver_call(
|
|
115
|
+
cursor.fetch(batch_size, timeout=self._replay_sql_seconds),
|
|
116
|
+
self._connection, self._replay_sql_seconds, self._cleanup_seconds,
|
|
117
|
+
)
|
|
118
|
+
rows.extend(batch)
|
|
119
|
+
if len(batch) < batch_size:
|
|
120
|
+
return rows
|
|
121
|
+
|
|
122
|
+
async def fetch_history_page(
|
|
123
|
+
self, query: str, *args: Any, batch_size: int = 8,
|
|
124
|
+
estimated_bytes: int | None = None,
|
|
125
|
+
) -> Any:
|
|
126
|
+
"""Transfer a bounded page inside the caller's read snapshot.
|
|
127
|
+
|
|
128
|
+
Start conservatively for large tool outputs, then grow only when the
|
|
129
|
+
observed transfer has command-budget headroom. Permanently fetching
|
|
130
|
+
eight rows makes a modest-RTT database exhaust the *total* deadline.
|
|
131
|
+
Growth is capped by both rows and observed payload bytes; slow/large
|
|
132
|
+
batches shrink again. SQL limit, snapshot, command and HTTP deadlines
|
|
133
|
+
remain unchanged. No failed query is retried.
|
|
134
|
+
"""
|
|
135
|
+
# The exact candidate preflight and this read share repeatable-read.
|
|
136
|
+
# A small complete body avoids cursor bind/empty-fetch round trips.
|
|
137
|
+
# Do not take this path when size is unknown (custom callers/tests).
|
|
138
|
+
if estimated_bytes is not None and estimated_bytes <= 256 * 1024:
|
|
139
|
+
return await self.fetch(query, *args)
|
|
140
|
+
if not callable(getattr(self._connection, "cursor", None)):
|
|
141
|
+
return await self.fetch(query, *args)
|
|
142
|
+
|
|
143
|
+
async def bind_cursor():
|
|
144
|
+
return await self._connection.cursor(query, *args, timeout=self._sql_seconds)
|
|
145
|
+
|
|
146
|
+
cursor = await bounded_driver_call(bind_cursor(), self._connection, self._sql_seconds,
|
|
147
|
+
self._cleanup_seconds)
|
|
148
|
+
rows = []
|
|
149
|
+
while True:
|
|
150
|
+
started = time.monotonic()
|
|
151
|
+
batch = await bounded_driver_call(
|
|
152
|
+
cursor.fetch(batch_size, timeout=self._sql_seconds),
|
|
153
|
+
self._connection, self._sql_seconds, self._cleanup_seconds,
|
|
154
|
+
)
|
|
155
|
+
elapsed = time.monotonic() - started
|
|
156
|
+
rows.extend(batch)
|
|
157
|
+
if len(batch) < batch_size:
|
|
158
|
+
return rows
|
|
159
|
+
# asyncpg returns JSON columns as text. Estimate the received body
|
|
160
|
+
# without decoding/copying whole SessionEvents. This is only a
|
|
161
|
+
# transfer heuristic; the exact SQL preflight remains the hard
|
|
162
|
+
# per-request byte guard.
|
|
163
|
+
body_bytes = sum(
|
|
164
|
+
len(value.encode('utf-8')) if isinstance(value, str)
|
|
165
|
+
else len(value) if isinstance(value, bytes) else 16
|
|
166
|
+
for row in batch for value in row.values()
|
|
167
|
+
)
|
|
168
|
+
byte_rows = max(1, batch_size * (256 * 1024) // max(1, body_bytes))
|
|
169
|
+
if elapsed < self._sql_seconds / 4:
|
|
170
|
+
batch_size = min(64, batch_size * 2, byte_rows)
|
|
171
|
+
elif elapsed > self._sql_seconds / 2:
|
|
172
|
+
batch_size = max(1, min(batch_size // 2, byte_rows))
|
|
173
|
+
else:
|
|
174
|
+
batch_size = min(batch_size, byte_rows)
|
|
175
|
+
|
|
176
|
+
async def fetchrow(self, query: str, *args: Any, **kwargs: Any) -> Any:
|
|
177
|
+
seconds = kwargs.pop("timeout", self._sql_seconds)
|
|
178
|
+
return await bounded_driver_call(
|
|
179
|
+
self._connection.fetchrow(query, *args, timeout=seconds, **kwargs),
|
|
180
|
+
self._connection, seconds, self._cleanup_seconds,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
async def fetchval(self, query: str, *args: Any, **kwargs: Any) -> Any:
|
|
184
|
+
seconds = kwargs.pop("timeout", self._sql_seconds)
|
|
185
|
+
return await bounded_driver_call(
|
|
186
|
+
self._connection.fetchval(query, *args, timeout=seconds, **kwargs),
|
|
187
|
+
self._connection, seconds, self._cleanup_seconds,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
@asynccontextmanager
|
|
191
|
+
async def transaction(self, *args: Any, **kwargs: Any) -> AsyncIterator[Any]:
|
|
192
|
+
transaction = self._connection.transaction(*args, **kwargs)
|
|
193
|
+
await bounded_driver_call(transaction.__aenter__(), self._connection,
|
|
194
|
+
self._sql_seconds, self._cleanup_seconds)
|
|
195
|
+
try:
|
|
196
|
+
yield transaction
|
|
197
|
+
except BaseException as exc:
|
|
198
|
+
try:
|
|
199
|
+
await bounded_cleanup(
|
|
200
|
+
transaction.__aexit__(type(exc), exc, exc.__traceback__),
|
|
201
|
+
self._connection, self._cleanup_seconds,
|
|
202
|
+
)
|
|
203
|
+
except Exception as cleanup_error:
|
|
204
|
+
# Preserve the operation failure while discarding an unusable
|
|
205
|
+
# connection. A terminated pool proxy may already be detached.
|
|
206
|
+
logger.warning("Transaction rollback failed (%s); discarding connection",
|
|
207
|
+
type(cleanup_error).__name__)
|
|
208
|
+
try:
|
|
209
|
+
self._connection.terminate()
|
|
210
|
+
except Exception:
|
|
211
|
+
logger.debug("Connection already unavailable during rollback", exc_info=True)
|
|
212
|
+
raise
|
|
213
|
+
else:
|
|
214
|
+
try:
|
|
215
|
+
await bounded_driver_call(transaction.__aexit__(None, None, None),
|
|
216
|
+
self._connection, self._sql_seconds, self._cleanup_seconds)
|
|
217
|
+
except TimeoutError:
|
|
218
|
+
raise
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class PostgresSessionService(_PostgresCheckpointReadMixin, _PostgresHistoryReadMixin, _PostgresToolReceiptMixin, _PostgresSchemaMixin, BaseSessionService):
|
|
222
|
+
# Its get/list/query/count operations never execute Agent or tool effects.
|
|
223
|
+
_retry_safe_reads = True
|
|
37
224
|
storage_capabilities = CANONICAL_EVENT_STORAGE_CAPABILITIES
|
|
38
225
|
|
|
226
|
+
@staticmethod
|
|
227
|
+
async def _precheck_history_body(
|
|
228
|
+
connection: _TimedConnection, candidate_sql: str, params: list[Any],
|
|
229
|
+
) -> int | None:
|
|
230
|
+
budget = CURRENT_HISTORY_READ_BUDGET.get()
|
|
231
|
+
if budget is None:
|
|
232
|
+
return
|
|
233
|
+
sizes = await connection.fetchrow(
|
|
234
|
+
"SELECT COALESCE(SUM(COALESCE(octet_length(content_json::text),0) + "
|
|
235
|
+
"COALESCE(octet_length(state_delta_json::text),0) + "
|
|
236
|
+
"COALESCE(octet_length(metadata_json::text),0)), 0) AS body_bytes, "
|
|
237
|
+
"COUNT(*) AS event_count "
|
|
238
|
+
f"FROM ({candidate_sql}) AS history_candidates",
|
|
239
|
+
*params,
|
|
240
|
+
)
|
|
241
|
+
size = int(sizes['body_bytes'])
|
|
242
|
+
# Preserve the conservative per-event allowance for the hard budget;
|
|
243
|
+
# it is not JSON payload and must not inflate the transfer estimate.
|
|
244
|
+
budget.account(size + 1024 * int(sizes['event_count']))
|
|
245
|
+
return size
|
|
246
|
+
|
|
39
247
|
def __init__(
|
|
40
248
|
self,
|
|
41
249
|
*,
|
|
@@ -45,7 +253,8 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
45
253
|
workspace_id: str = "default",
|
|
46
254
|
min_size: int = 1,
|
|
47
255
|
max_size: int = 10,
|
|
48
|
-
connect_timeout: float =
|
|
256
|
+
connect_timeout: float | None = None,
|
|
257
|
+
db_budget: DatabaseBudget | None = None,
|
|
49
258
|
):
|
|
50
259
|
if not dsn.strip():
|
|
51
260
|
raise ValueError("KSADK_SESSION_DSN is required when KSADK_SESSION_BACKEND=postgres")
|
|
@@ -55,7 +264,8 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
55
264
|
self.workspace_id = workspace_id.strip() or "default"
|
|
56
265
|
self.min_size = min_size
|
|
57
266
|
self.max_size = max_size
|
|
58
|
-
self.
|
|
267
|
+
self.db_budget = db_budget or session_db_budget()
|
|
268
|
+
self.connect_timeout = connect_timeout or self.db_budget.connect_seconds
|
|
59
269
|
self._pool: Any = None
|
|
60
270
|
self._pool_lock = asyncio.Lock()
|
|
61
271
|
self._schema_ready = False
|
|
@@ -63,7 +273,80 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
63
273
|
self._checkpoint_snapshot_connection: ContextVar[Any | None] = ContextVar(
|
|
64
274
|
f"checkpoint_snapshot_connection_{id(self)}", default=None
|
|
65
275
|
)
|
|
276
|
+
self._history_read_lease: ContextVar[Any | None] = ContextVar(
|
|
277
|
+
f"history_read_lease_{id(self)}", default=None
|
|
278
|
+
)
|
|
279
|
+
try:
|
|
280
|
+
transfers = max(1, min(32, int(os.getenv("KSADK_HISTORY_READ_CONCURRENCY", "4"))))
|
|
281
|
+
except ValueError:
|
|
282
|
+
transfers = 4
|
|
283
|
+
self._history_transfer_slots = asyncio.Semaphore(transfers)
|
|
284
|
+
|
|
285
|
+
@asynccontextmanager
|
|
286
|
+
async def history_read_scope(self) -> AsyncIterator[None]:
|
|
287
|
+
"""Reuse one lease for a bounded, serial message projection.
|
|
288
|
+
|
|
289
|
+
This does not start a transaction or cache authorization. The caller
|
|
290
|
+
keeps its seq snapshot and operation deadline. Child tasks and writes
|
|
291
|
+
must acquire their own connection; asyncpg cannot multiplex a lease.
|
|
292
|
+
"""
|
|
293
|
+
await self._ensure_schema()
|
|
294
|
+
async with self._connection() as connection:
|
|
295
|
+
token = self._history_read_lease.set((asyncio.current_task(), connection))
|
|
296
|
+
try:
|
|
297
|
+
yield
|
|
298
|
+
finally:
|
|
299
|
+
self._history_read_lease.reset(token)
|
|
300
|
+
|
|
301
|
+
@asynccontextmanager
|
|
302
|
+
async def _connection(self, *, write: bool = False) -> AsyncIterator[_TimedConnection]:
|
|
303
|
+
shared = self._history_read_lease.get()
|
|
304
|
+
if not write and shared is not None and shared[0] is asyncio.current_task():
|
|
305
|
+
import asyncpg
|
|
306
|
+
connection = shared[1]
|
|
307
|
+
try:
|
|
308
|
+
closed = connection.is_closed()
|
|
309
|
+
except asyncpg.InterfaceError:
|
|
310
|
+
closed = True # Termination can detach the pool proxy first.
|
|
311
|
+
if not closed:
|
|
312
|
+
yield connection
|
|
313
|
+
return
|
|
314
|
+
# A terminated transport may be retried by the existing read-only
|
|
315
|
+
# recovery path. Never hand that path the same dead connection.
|
|
316
|
+
# Keep the scope marker so replacement reads still use its gate.
|
|
317
|
+
budget = self.db_budget
|
|
318
|
+
acquire = budget.write_acquire_seconds if write else budget.read_acquire_seconds
|
|
319
|
+
sql = budget.write_sql_seconds if write else budget.read_sql_seconds
|
|
320
|
+
lease = None
|
|
321
|
+
connection = None
|
|
322
|
+
token = _cleanup_deadline.set(None)
|
|
323
|
+
try:
|
|
324
|
+
if write:
|
|
325
|
+
async with asyncio.timeout(budget.write_operation_seconds):
|
|
326
|
+
lease = self._pool.acquire(timeout=acquire)
|
|
327
|
+
connection = await asyncio.wait_for(lease.__aenter__(), timeout=acquire)
|
|
328
|
+
yield _TimedConnection(connection, sql, budget.cleanup_seconds, budget.replay_operation_seconds, budget.replay_sql_seconds)
|
|
329
|
+
else:
|
|
330
|
+
lease = self._pool.acquire(timeout=acquire)
|
|
331
|
+
connection = await asyncio.wait_for(lease.__aenter__(), timeout=acquire)
|
|
332
|
+
yield _TimedConnection(connection, sql, budget.cleanup_seconds, budget.replay_operation_seconds, budget.replay_sql_seconds)
|
|
333
|
+
finally:
|
|
334
|
+
if lease is not None and connection is not None:
|
|
335
|
+
try:
|
|
336
|
+
await release_pool_lease(self._pool, lease, connection,
|
|
337
|
+
budget.cleanup_seconds)
|
|
338
|
+
finally:
|
|
339
|
+
_cleanup_deadline.reset(token)
|
|
340
|
+
else:
|
|
341
|
+
_cleanup_deadline.reset(token)
|
|
342
|
+
|
|
343
|
+
async def _set_lock_timeout(self, connection: _TimedConnection) -> None:
|
|
344
|
+
milliseconds = max(1, int(self.db_budget.lock_seconds * 1000))
|
|
345
|
+
await connection.fetchval(
|
|
346
|
+
"SELECT set_config('lock_timeout', $1, true)", f"{milliseconds}ms"
|
|
347
|
+
)
|
|
66
348
|
|
|
349
|
+
@_write_deadline
|
|
67
350
|
async def create_session(
|
|
68
351
|
self,
|
|
69
352
|
agent_id: str,
|
|
@@ -72,9 +355,12 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
72
355
|
) -> Session:
|
|
73
356
|
await self._ensure_schema()
|
|
74
357
|
session_key = session_id or new_session_id()
|
|
75
|
-
async with self.
|
|
358
|
+
async with self._connection(write=True) as connection:
|
|
76
359
|
async with connection.transaction():
|
|
77
|
-
|
|
360
|
+
await self._set_lock_timeout(connection)
|
|
361
|
+
existing = await self._get_session_with_connection(
|
|
362
|
+
connection, session_key, include_events=False
|
|
363
|
+
)
|
|
78
364
|
if existing is not None:
|
|
79
365
|
return existing
|
|
80
366
|
|
|
@@ -129,18 +415,124 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
129
415
|
|
|
130
416
|
async def get_session(self, session_id: str) -> Optional[Session]:
|
|
131
417
|
await self._ensure_schema()
|
|
132
|
-
async with self.
|
|
418
|
+
async with self._connection() as connection:
|
|
133
419
|
return await self._get_session_with_connection(connection, session_id)
|
|
134
420
|
|
|
421
|
+
async def get_adk_session_snapshot(
|
|
422
|
+
self, session_id: str, expected_session: Session | None = None
|
|
423
|
+
) -> Optional[Session]:
|
|
424
|
+
"""Read ownership, state, and the complete transcript from one snapshot."""
|
|
425
|
+
await self._ensure_schema()
|
|
426
|
+
async with self._connection() as connection:
|
|
427
|
+
async with connection.transaction(isolation="repeatable_read", readonly=True):
|
|
428
|
+
session = await self._get_session_with_connection(connection, session_id)
|
|
429
|
+
if expected_session is not None and (
|
|
430
|
+
session is None or session.agent_id != expected_session.agent_id
|
|
431
|
+
or session.user_id != expected_session.user_id
|
|
432
|
+
or session.created_at != expected_session.created_at
|
|
433
|
+
):
|
|
434
|
+
from ksadk.sessions.errors import HistoryReloadRequired
|
|
435
|
+
|
|
436
|
+
raise HistoryReloadRequired("Session changed during legacy read")
|
|
437
|
+
return session
|
|
438
|
+
|
|
135
439
|
async def get_session_metadata(self, session_id: str) -> Optional[Session]:
|
|
136
440
|
await self._ensure_schema()
|
|
137
|
-
async with self.
|
|
441
|
+
async with self._connection() as connection:
|
|
138
442
|
return await self._get_session_with_connection(
|
|
139
443
|
connection,
|
|
140
444
|
session_id,
|
|
141
445
|
include_events=False,
|
|
142
446
|
)
|
|
143
447
|
|
|
448
|
+
async def get_session_header(self, session_id: str) -> Optional[Session]:
|
|
449
|
+
"""History authorization/epoch fields without reading the state blob."""
|
|
450
|
+
await self._ensure_schema()
|
|
451
|
+
async with self._connection() as connection:
|
|
452
|
+
row = await connection.fetchrow(
|
|
453
|
+
f"SELECT id,agent_id,user_id,title,title_source,summary,first_prompt,"
|
|
454
|
+
f"last_prompt,created_at,updated_at,version FROM {KSADK_PG_SESSIONS_TABLE} "
|
|
455
|
+
"WHERE namespace=$1 AND id=$2",
|
|
456
|
+
self.namespace, session_id,
|
|
457
|
+
)
|
|
458
|
+
if row is None:
|
|
459
|
+
return None
|
|
460
|
+
return self._header_from_row(row)
|
|
461
|
+
|
|
462
|
+
@staticmethod
|
|
463
|
+
def _header_from_row(row: Any) -> Session:
|
|
464
|
+
return Session(
|
|
465
|
+
id=row["id"], agent_id=row["agent_id"], user_id=row["user_id"],
|
|
466
|
+
title=row["title"], title_source=row["title_source"],
|
|
467
|
+
summary=row["summary"], first_prompt=row["first_prompt"],
|
|
468
|
+
last_prompt=row["last_prompt"], created_at=float(row["created_at"]),
|
|
469
|
+
updated_at=float(row["updated_at"]), version=int(row["version"] or 0),
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
async def get_session_header_with_watermark(self, session_id: str) -> tuple[Session | None, int]:
|
|
473
|
+
"""One statement snapshot for history authorization and its high watermark."""
|
|
474
|
+
if type(self).get_session_header is not PostgresSessionService.get_session_header:
|
|
475
|
+
# A custom backend may add ownership policy in its header loader.
|
|
476
|
+
header = await self.get_session_header(session_id)
|
|
477
|
+
return header, await self.get_max_seq_id(session_id) if header is not None else 0
|
|
478
|
+
await self._ensure_schema()
|
|
479
|
+
async with self._connection() as connection:
|
|
480
|
+
row = await connection.fetchrow(
|
|
481
|
+
f"SELECT s.id,s.agent_id,s.user_id,s.title,s.title_source,s.summary,"
|
|
482
|
+
"s.first_prompt,s.last_prompt,s.created_at,s.updated_at,s.version,"
|
|
483
|
+
f"(SELECT MAX(e.seq_id) FROM {KSADK_PG_EVENTS_TABLE} e "
|
|
484
|
+
"WHERE e.namespace=s.namespace AND e.session_id=s.id) AS newest_seq "
|
|
485
|
+
f"FROM {KSADK_PG_SESSIONS_TABLE} s WHERE s.namespace=$1 AND s.id=$2",
|
|
486
|
+
self.namespace, session_id,
|
|
487
|
+
)
|
|
488
|
+
return (self._header_from_row(row), int(row['newest_seq'] or 0)) if row else (None, 0)
|
|
489
|
+
|
|
490
|
+
@_write_deadline
|
|
491
|
+
async def ensure_session_header(
|
|
492
|
+
self, agent_id: str, user_id: str, session_id: str
|
|
493
|
+
) -> Session:
|
|
494
|
+
"""Create a canonical session without reading state or event bodies on races."""
|
|
495
|
+
await self._ensure_schema()
|
|
496
|
+
now = time.time()
|
|
497
|
+
async with self._connection(write=True) as connection:
|
|
498
|
+
async with connection.transaction():
|
|
499
|
+
await self._set_lock_timeout(connection)
|
|
500
|
+
inserted = await connection.fetchval(
|
|
501
|
+
f"INSERT INTO {KSADK_PG_SESSIONS_TABLE} ("
|
|
502
|
+
"namespace,tenant_id,workspace_id,id,agent_id,user_id,title,"
|
|
503
|
+
"title_source,summary,first_prompt,last_prompt,state_json,"
|
|
504
|
+
"created_at,updated_at,version) VALUES "
|
|
505
|
+
"($1,$2,$3,$4,$5,$6,'','','','','','{}'::jsonb,$7,$7,0) "
|
|
506
|
+
"ON CONFLICT (namespace,id) DO NOTHING RETURNING id",
|
|
507
|
+
self.namespace, self.tenant_id, self.workspace_id,
|
|
508
|
+
session_id, agent_id, user_id, now,
|
|
509
|
+
)
|
|
510
|
+
row = await connection.fetchrow(
|
|
511
|
+
f"SELECT id,agent_id,user_id,title,title_source,summary,"
|
|
512
|
+
f"first_prompt,last_prompt,created_at,updated_at,version "
|
|
513
|
+
f"FROM {KSADK_PG_SESSIONS_TABLE} WHERE namespace=$1 AND id=$2",
|
|
514
|
+
self.namespace, session_id,
|
|
515
|
+
)
|
|
516
|
+
if row is None:
|
|
517
|
+
raise RuntimeError("Canonical AG-UI session creation was not visible")
|
|
518
|
+
if inserted is not None:
|
|
519
|
+
await connection.execute(
|
|
520
|
+
f"INSERT INTO {KSADK_PG_STATES_TABLE} ("
|
|
521
|
+
"namespace,tenant_id,workspace_id,scope,agent_id,user_id,"
|
|
522
|
+
"session_id,state_json,version,updated_at) VALUES "
|
|
523
|
+
"($1,$2,$3,'session',$4,$5,$6,'{}'::jsonb,0,$7) "
|
|
524
|
+
"ON CONFLICT (namespace,scope,agent_id,user_id,session_id) DO NOTHING",
|
|
525
|
+
self.namespace, self.tenant_id, self.workspace_id,
|
|
526
|
+
row["agent_id"], row["user_id"], session_id, now,
|
|
527
|
+
)
|
|
528
|
+
return Session(
|
|
529
|
+
id=row["id"], agent_id=row["agent_id"], user_id=row["user_id"],
|
|
530
|
+
title=row["title"], title_source=row["title_source"],
|
|
531
|
+
summary=row["summary"], first_prompt=row["first_prompt"],
|
|
532
|
+
last_prompt=row["last_prompt"], created_at=float(row["created_at"]),
|
|
533
|
+
updated_at=float(row["updated_at"]), version=int(row["version"] or 0),
|
|
534
|
+
)
|
|
535
|
+
|
|
144
536
|
async def list_sessions(
|
|
145
537
|
self,
|
|
146
538
|
agent_id: str,
|
|
@@ -149,7 +541,7 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
149
541
|
limit: Optional[int] = None,
|
|
150
542
|
) -> list[Session]:
|
|
151
543
|
await self._ensure_schema()
|
|
152
|
-
async with self.
|
|
544
|
+
async with self._connection() as connection:
|
|
153
545
|
query = f"""
|
|
154
546
|
SELECT id, agent_id, user_id, title, title_source, summary,
|
|
155
547
|
first_prompt, last_prompt,
|
|
@@ -180,7 +572,7 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
180
572
|
user_id: Optional[str] = None,
|
|
181
573
|
) -> int:
|
|
182
574
|
await self._ensure_schema()
|
|
183
|
-
async with self.
|
|
575
|
+
async with self._connection() as connection:
|
|
184
576
|
query = f"""
|
|
185
577
|
SELECT COUNT(*) AS total
|
|
186
578
|
FROM {KSADK_PG_SESSIONS_TABLE}
|
|
@@ -192,10 +584,25 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
192
584
|
query += f" AND user_id = ${len(params)}"
|
|
193
585
|
return int(await connection.fetchval(query, *params) or 0)
|
|
194
586
|
|
|
587
|
+
@_write_deadline
|
|
195
588
|
async def delete_session(self, session_id: str) -> bool:
|
|
196
589
|
await self._ensure_schema()
|
|
197
|
-
async with self.
|
|
590
|
+
async with self._connection(write=True) as connection:
|
|
198
591
|
async with connection.transaction():
|
|
592
|
+
await self._set_lock_timeout(connection)
|
|
593
|
+
if not await connection.fetchval(
|
|
594
|
+
f"SELECT 1 FROM {KSADK_PG_SESSIONS_TABLE} "
|
|
595
|
+
"WHERE namespace=$1 AND id=$2 FOR UPDATE",
|
|
596
|
+
self.namespace, session_id,
|
|
597
|
+
):
|
|
598
|
+
return False
|
|
599
|
+
if await connection.fetchval(
|
|
600
|
+
f"SELECT 1 FROM {pg_tool_receipts_table} "
|
|
601
|
+
"WHERE namespace=$1 AND session_id=$2 AND state='unknown' LIMIT 1",
|
|
602
|
+
self.namespace,
|
|
603
|
+
session_id,
|
|
604
|
+
):
|
|
605
|
+
raise ValueError("session has durable tool receipt claims")
|
|
199
606
|
await connection.execute(
|
|
200
607
|
f"""
|
|
201
608
|
DELETE FROM {KSADK_PG_STATES_TABLE}
|
|
@@ -214,6 +621,7 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
214
621
|
)
|
|
215
622
|
return not result.endswith(" 0")
|
|
216
623
|
|
|
624
|
+
@_write_deadline
|
|
217
625
|
async def update_session_metadata(
|
|
218
626
|
self,
|
|
219
627
|
session_id: str,
|
|
@@ -225,8 +633,9 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
225
633
|
last_prompt: Optional[str] = None,
|
|
226
634
|
) -> Session:
|
|
227
635
|
await self._ensure_schema()
|
|
228
|
-
async with self.
|
|
636
|
+
async with self._connection(write=True) as connection:
|
|
229
637
|
async with connection.transaction():
|
|
638
|
+
await self._set_lock_timeout(connection)
|
|
230
639
|
row = await connection.fetchrow(
|
|
231
640
|
f"""
|
|
232
641
|
SELECT id, agent_id, user_id, title, title_source, summary,
|
|
@@ -278,13 +687,29 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
278
687
|
version=row["version"],
|
|
279
688
|
)
|
|
280
689
|
|
|
690
|
+
@_write_deadline
|
|
281
691
|
async def append_event(self, session_id: str, event: SessionEvent) -> SessionEvent:
|
|
692
|
+
return await self._append_event_with_expected(session_id, event, None)
|
|
693
|
+
|
|
694
|
+
@_write_deadline
|
|
695
|
+
async def append_event_if_session_matches(
|
|
696
|
+
self, session_id: str, event: SessionEvent, expected_session: Session
|
|
697
|
+
) -> SessionEvent:
|
|
698
|
+
return await self._append_event_with_expected(session_id, event, expected_session)
|
|
699
|
+
|
|
700
|
+
async def _append_event_with_expected(
|
|
701
|
+
self, session_id: str, event: SessionEvent, expected_session: Session | None
|
|
702
|
+
) -> SessionEvent:
|
|
282
703
|
await self._ensure_schema()
|
|
283
|
-
|
|
704
|
+
# No-delta events still lock the session row to allocate a fenced
|
|
705
|
+
# sequence, but do not fetch/decode a potentially large state value.
|
|
706
|
+
state_column = ", state_json" if event.state_delta else ""
|
|
707
|
+
async with self._connection(write=True) as connection:
|
|
284
708
|
async with connection.transaction():
|
|
709
|
+
await self._set_lock_timeout(connection)
|
|
285
710
|
session_row = await connection.fetchrow(
|
|
286
711
|
f"""
|
|
287
|
-
SELECT agent_id, user_id,
|
|
712
|
+
SELECT agent_id, user_id, created_at, version{state_column}
|
|
288
713
|
FROM {KSADK_PG_SESSIONS_TABLE}
|
|
289
714
|
WHERE namespace = $1 AND id = $2
|
|
290
715
|
FOR UPDATE
|
|
@@ -294,6 +719,14 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
294
719
|
)
|
|
295
720
|
if session_row is None:
|
|
296
721
|
raise ValueError(f"Session {session_id} not found")
|
|
722
|
+
if expected_session is not None and (
|
|
723
|
+
session_row["agent_id"] != expected_session.agent_id
|
|
724
|
+
or session_row["user_id"] != expected_session.user_id
|
|
725
|
+
or float(session_row["created_at"]) != expected_session.created_at
|
|
726
|
+
):
|
|
727
|
+
from ksadk.sessions.errors import HistoryReloadRequired
|
|
728
|
+
|
|
729
|
+
raise HistoryReloadRequired("Session changed during legacy import")
|
|
297
730
|
|
|
298
731
|
next_seq = await connection.fetchval(
|
|
299
732
|
f"""
|
|
@@ -346,25 +779,38 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
346
779
|
)
|
|
347
780
|
|
|
348
781
|
updated_at = time.time()
|
|
349
|
-
state = self._json_to_dict(session_row["state_json"])
|
|
350
|
-
version = int(session_row["version"] or 0)
|
|
351
782
|
if stored.state_delta:
|
|
783
|
+
state = self._json_to_dict(session_row["state_json"])
|
|
784
|
+
version = int(session_row["version"] or 0)
|
|
352
785
|
state.update(stored.state_delta)
|
|
353
786
|
version += 1
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
787
|
+
await self._write_session_state(
|
|
788
|
+
connection,
|
|
789
|
+
session_id=session_id,
|
|
790
|
+
agent_id=session_row["agent_id"],
|
|
791
|
+
user_id=session_row["user_id"],
|
|
792
|
+
state=state,
|
|
793
|
+
version=version,
|
|
794
|
+
updated_at=updated_at,
|
|
795
|
+
)
|
|
796
|
+
else:
|
|
797
|
+
await connection.execute(
|
|
798
|
+
f"UPDATE {KSADK_PG_SESSIONS_TABLE} SET updated_at=$1 "
|
|
799
|
+
"WHERE namespace=$2 AND id=$3",
|
|
800
|
+
updated_at, self.namespace, session_id,
|
|
801
|
+
)
|
|
363
802
|
return stored
|
|
364
803
|
|
|
365
804
|
async def get_event_by_id(self, session_id: str, event_id: str) -> Optional[SessionEvent]:
|
|
805
|
+
return await self._get_event_by_id(session_id, event_id, write=False)
|
|
806
|
+
|
|
807
|
+
async def get_event_by_id_for_write(self, session_id: str, event_id: str) -> Optional[SessionEvent]:
|
|
808
|
+
"""Canonical idempotency/commit lookup is part of a storage write."""
|
|
809
|
+
return await self._get_event_by_id(session_id, event_id, write=True)
|
|
810
|
+
|
|
811
|
+
async def _get_event_by_id(self, session_id: str, event_id: str, *, write: bool) -> Optional[SessionEvent]:
|
|
366
812
|
await self._ensure_schema()
|
|
367
|
-
async with self.
|
|
813
|
+
async with self._connection(write=write) as connection:
|
|
368
814
|
row = await connection.fetchrow(
|
|
369
815
|
f"""
|
|
370
816
|
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
@@ -378,6 +824,33 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
378
824
|
)
|
|
379
825
|
return self._event_from_row(row) if row is not None else None
|
|
380
826
|
|
|
827
|
+
async def get_event_by_id_if_session_matches(
|
|
828
|
+
self, session_id: str, event_id: str, expected_session: Session
|
|
829
|
+
) -> Optional[SessionEvent]:
|
|
830
|
+
"""Confirm one stable event ID under the authorized session incarnation."""
|
|
831
|
+
await self._ensure_schema()
|
|
832
|
+
async with self._connection() as connection:
|
|
833
|
+
async with connection.transaction(isolation="repeatable_read", readonly=True):
|
|
834
|
+
owner = await connection.fetchrow(
|
|
835
|
+
f"SELECT agent_id,user_id,created_at FROM {KSADK_PG_SESSIONS_TABLE} "
|
|
836
|
+
"WHERE namespace=$1 AND id=$2",
|
|
837
|
+
self.namespace, session_id,
|
|
838
|
+
)
|
|
839
|
+
if (owner is None or owner["agent_id"] != expected_session.agent_id
|
|
840
|
+
or owner["user_id"] != expected_session.user_id
|
|
841
|
+
or float(owner["created_at"]) != expected_session.created_at):
|
|
842
|
+
from ksadk.sessions.errors import HistoryReloadRequired
|
|
843
|
+
|
|
844
|
+
raise HistoryReloadRequired("Session changed during legacy import")
|
|
845
|
+
row = await connection.fetchrow(
|
|
846
|
+
f"SELECT id,session_id,author,event_type,content_json,timestamp,"
|
|
847
|
+
f"state_delta_json,seq_id,invocation_id,metadata_json "
|
|
848
|
+
f"FROM {KSADK_PG_EVENTS_TABLE} "
|
|
849
|
+
"WHERE namespace=$1 AND session_id=$2 AND id=$3",
|
|
850
|
+
self.namespace, session_id, event_id,
|
|
851
|
+
)
|
|
852
|
+
return self._event_from_row(row) if row is not None else None
|
|
853
|
+
|
|
381
854
|
async def get_events_by_invocation_id(
|
|
382
855
|
self,
|
|
383
856
|
session_id: str,
|
|
@@ -395,7 +868,7 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
395
868
|
if before_seq_id is not None:
|
|
396
869
|
params.append(before_seq_id)
|
|
397
870
|
conditions.append(f"seq_id < ${len(params)}")
|
|
398
|
-
async with self.
|
|
871
|
+
async with self._connection() as connection:
|
|
399
872
|
rows = await connection.fetch(
|
|
400
873
|
f"""
|
|
401
874
|
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
@@ -408,523 +881,13 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
408
881
|
)
|
|
409
882
|
return [self._event_from_row(row) for row in rows]
|
|
410
883
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
session_id
|
|
414
|
-
offset: Optional[int] = None,
|
|
415
|
-
limit: Optional[int] = None,
|
|
416
|
-
after_seq_id: Optional[int] = None,
|
|
417
|
-
before_seq_id: Optional[int] = None,
|
|
418
|
-
) -> list[SessionEvent]:
|
|
419
|
-
await self._ensure_schema()
|
|
420
|
-
# seq 过滤先应用,再对结果集应用"最新 N 条" offset/limit 语义。
|
|
421
|
-
conditions = ["namespace = $1", "session_id = $2"]
|
|
422
|
-
params: list[Any] = [self.namespace, session_id]
|
|
423
|
-
if after_seq_id is not None:
|
|
424
|
-
params.append(after_seq_id)
|
|
425
|
-
conditions.append(f"seq_id > ${len(params)}")
|
|
426
|
-
if before_seq_id is not None:
|
|
427
|
-
params.append(before_seq_id)
|
|
428
|
-
conditions.append(f"seq_id < ${len(params)}")
|
|
429
|
-
where_clause = " AND ".join(conditions)
|
|
430
|
-
async with self._pool.acquire() as connection:
|
|
431
|
-
if limit is not None:
|
|
432
|
-
params.extend([limit, offset or 0])
|
|
433
|
-
limit_param = len(params) - 1
|
|
434
|
-
offset_param = len(params)
|
|
435
|
-
query = f"""
|
|
436
|
-
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
437
|
-
state_delta_json, seq_id, invocation_id, metadata_json
|
|
438
|
-
FROM (
|
|
439
|
-
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
440
|
-
state_delta_json, seq_id, invocation_id, metadata_json
|
|
441
|
-
FROM {KSADK_PG_EVENTS_TABLE}
|
|
442
|
-
WHERE {where_clause}
|
|
443
|
-
ORDER BY seq_id DESC
|
|
444
|
-
LIMIT ${limit_param} OFFSET ${offset_param}
|
|
445
|
-
) AS latest_events
|
|
446
|
-
ORDER BY seq_id ASC
|
|
447
|
-
"""
|
|
448
|
-
elif offset is not None:
|
|
449
|
-
params.append(offset)
|
|
450
|
-
offset_param = len(params)
|
|
451
|
-
query = f"""
|
|
452
|
-
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
453
|
-
state_delta_json, seq_id, invocation_id, metadata_json
|
|
454
|
-
FROM (
|
|
455
|
-
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
456
|
-
state_delta_json, seq_id, invocation_id, metadata_json
|
|
457
|
-
FROM {KSADK_PG_EVENTS_TABLE}
|
|
458
|
-
WHERE {where_clause}
|
|
459
|
-
ORDER BY seq_id DESC
|
|
460
|
-
OFFSET ${offset_param}
|
|
461
|
-
) AS latest_events
|
|
462
|
-
ORDER BY seq_id ASC
|
|
463
|
-
"""
|
|
464
|
-
else:
|
|
465
|
-
query = f"""
|
|
466
|
-
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
467
|
-
state_delta_json, seq_id, invocation_id, metadata_json
|
|
468
|
-
FROM {KSADK_PG_EVENTS_TABLE}
|
|
469
|
-
WHERE {where_clause}
|
|
470
|
-
ORDER BY seq_id ASC
|
|
471
|
-
"""
|
|
472
|
-
rows = await connection.fetch(query, *params)
|
|
473
|
-
return [self._event_from_row(row) for row in rows]
|
|
474
|
-
|
|
475
|
-
async def count_events(
|
|
476
|
-
self,
|
|
477
|
-
session_id: str,
|
|
478
|
-
after_seq_id: Optional[int] = None,
|
|
479
|
-
before_seq_id: Optional[int] = None,
|
|
480
|
-
) -> int:
|
|
481
|
-
await self._ensure_schema()
|
|
482
|
-
conditions = ["namespace = $1", "session_id = $2"]
|
|
483
|
-
params: list[Any] = [self.namespace, session_id]
|
|
484
|
-
if after_seq_id is not None:
|
|
485
|
-
params.append(after_seq_id)
|
|
486
|
-
conditions.append(f"seq_id > ${len(params)}")
|
|
487
|
-
if before_seq_id is not None:
|
|
488
|
-
params.append(before_seq_id)
|
|
489
|
-
conditions.append(f"seq_id < ${len(params)}")
|
|
490
|
-
where_clause = " AND ".join(conditions)
|
|
491
|
-
async with self._pool.acquire() as connection:
|
|
492
|
-
query = f"""
|
|
493
|
-
SELECT COUNT(*) AS total
|
|
494
|
-
FROM {KSADK_PG_EVENTS_TABLE}
|
|
495
|
-
WHERE {where_clause}
|
|
496
|
-
"""
|
|
497
|
-
return int(await connection.fetchval(query, *params) or 0)
|
|
498
|
-
|
|
499
|
-
async def get_sessions_by_ids(self, session_ids: list[str]) -> list[Session]:
|
|
500
|
-
if not session_ids:
|
|
501
|
-
return []
|
|
502
|
-
await self._ensure_schema()
|
|
503
|
-
async with self._pool.acquire() as connection:
|
|
504
|
-
rows = await connection.fetch(
|
|
505
|
-
f"SELECT id,agent_id,user_id,title,title_source,summary,first_prompt,"
|
|
506
|
-
f"last_prompt,state_json,created_at,updated_at,version "
|
|
507
|
-
f"FROM {KSADK_PG_SESSIONS_TABLE} WHERE namespace=$1 "
|
|
508
|
-
"AND id=ANY($2::text[])",
|
|
509
|
-
self.namespace,
|
|
510
|
-
session_ids,
|
|
511
|
-
)
|
|
512
|
-
by_id = {row["id"]: self._session_from_row(row, events=[]) for row in rows}
|
|
513
|
-
return [by_id[item] for item in session_ids if item in by_id]
|
|
514
|
-
|
|
515
|
-
async def list_session_metadata(
|
|
516
|
-
self, agent_id: Optional[str] = None, user_id: Optional[str] = None
|
|
517
|
-
) -> list[Session]:
|
|
518
|
-
await self._ensure_schema()
|
|
519
|
-
clauses = ["namespace=$1"]
|
|
520
|
-
params: list[Any] = [self.namespace]
|
|
521
|
-
if agent_id is not None:
|
|
522
|
-
params.append(agent_id)
|
|
523
|
-
clauses.append(f"agent_id=${len(params)}")
|
|
524
|
-
if user_id is not None:
|
|
525
|
-
params.append(user_id)
|
|
526
|
-
clauses.append(f"user_id=${len(params)}")
|
|
527
|
-
async with self._pool.acquire() as connection:
|
|
528
|
-
rows = await connection.fetch(
|
|
529
|
-
f"SELECT id,agent_id,user_id,title,title_source,summary,first_prompt,"
|
|
530
|
-
f"last_prompt,state_json,created_at,updated_at,version "
|
|
531
|
-
f"FROM {KSADK_PG_SESSIONS_TABLE} WHERE {' AND '.join(clauses)} "
|
|
532
|
-
"ORDER BY updated_at DESC,created_at DESC,id DESC",
|
|
533
|
-
*params,
|
|
534
|
-
)
|
|
535
|
-
return [self._session_from_row(row, events=[]) for row in rows]
|
|
536
|
-
|
|
537
|
-
def _batch_event_where(self, query: SessionEventQuery) -> tuple[list[str], list[Any]]:
|
|
538
|
-
clauses = ["event_row.namespace=$1"]
|
|
539
|
-
params: list[Any] = [self.namespace]
|
|
540
|
-
if query.session_ids is not None:
|
|
541
|
-
if not query.session_ids:
|
|
542
|
-
return ["FALSE"], []
|
|
543
|
-
params.append(query.session_ids)
|
|
544
|
-
clauses.append(f"event_row.session_id=ANY(${len(params)}::text[])")
|
|
545
|
-
for value, clause in (
|
|
546
|
-
(query.agent_id, "session_row.agent_id"),
|
|
547
|
-
(query.after_seq_id, "event_row.seq_id >"),
|
|
548
|
-
(query.before_seq_id, "event_row.seq_id <"),
|
|
549
|
-
(query.invocation_id, "event_row.invocation_id"),
|
|
550
|
-
):
|
|
551
|
-
if value is not None:
|
|
552
|
-
params.append(value)
|
|
553
|
-
operator = "" if clause.endswith((">", "<")) else "="
|
|
554
|
-
clauses.append(f"{clause}{operator}${len(params)}")
|
|
555
|
-
if query.event_types:
|
|
556
|
-
params.append(query.event_types)
|
|
557
|
-
clauses.append(f"event_row.event_type=ANY(${len(params)}::text[])")
|
|
558
|
-
if query.run_id is not None:
|
|
559
|
-
params.append(query.run_id)
|
|
560
|
-
clauses.append(
|
|
561
|
-
"(event_row.metadata_json->>'run_id'="
|
|
562
|
-
f"${len(params)}"
|
|
563
|
-
" OR (event_row.event_type='continuation.created'"
|
|
564
|
-
f" AND event_row.content_json->'runtime_event'->>'run_id'=${len(params)}))"
|
|
565
|
-
)
|
|
566
|
-
if query.checkpoint_id is not None:
|
|
567
|
-
params.append(query.checkpoint_id)
|
|
568
|
-
clauses.append(
|
|
569
|
-
"(event_row.metadata_json->>'checkpoint_id'="
|
|
570
|
-
f"${len(params)}"
|
|
571
|
-
" OR (event_row.event_type='continuation.created'"
|
|
572
|
-
f" AND event_row.content_json->'runtime_event'->>'continuation_id'=${len(params)}))"
|
|
573
|
-
)
|
|
574
|
-
if query.checkpoint_ids:
|
|
575
|
-
params.append(query.checkpoint_ids)
|
|
576
|
-
clauses.append(
|
|
577
|
-
"(event_row.metadata_json->>'checkpoint_id'=ANY("
|
|
578
|
-
f"${len(params)}::text[])"
|
|
579
|
-
" OR (event_row.event_type='continuation.created'"
|
|
580
|
-
" AND event_row.content_json->'runtime_event'->>'continuation_id'=ANY("
|
|
581
|
-
f"${len(params)}::text[])))"
|
|
582
|
-
)
|
|
583
|
-
return clauses, params
|
|
884
|
+
@_write_deadline
|
|
885
|
+
async def claim_tool_receipt(self, session_id: str, **kwargs):
|
|
886
|
+
return await super().claim_tool_receipt(session_id, **kwargs)
|
|
584
887
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
direction = "ASC" if query.from_start else "DESC"
|
|
589
|
-
order = (
|
|
590
|
-
f"event_row.session_id {direction},event_row.seq_id {direction},"
|
|
591
|
-
f"event_row.id {direction}"
|
|
592
|
-
if query.order_by_seq
|
|
593
|
-
else f"event_row.timestamp {direction},event_row.session_id {direction},"
|
|
594
|
-
f"event_row.seq_id {direction},event_row.id {direction}"
|
|
595
|
-
)
|
|
596
|
-
params.extend([query.limit, query.offset])
|
|
597
|
-
async with self._pool.acquire() as connection:
|
|
598
|
-
rows = await connection.fetch(
|
|
599
|
-
f"SELECT event_row.id,event_row.session_id,event_row.author,event_row.event_type,"
|
|
600
|
-
f"event_row.content_json,event_row.timestamp,event_row.state_delta_json,"
|
|
601
|
-
f"event_row.seq_id,event_row.invocation_id,event_row.metadata_json "
|
|
602
|
-
f"FROM {KSADK_PG_EVENTS_TABLE} event_row "
|
|
603
|
-
f"JOIN {KSADK_PG_SESSIONS_TABLE} session_row "
|
|
604
|
-
"ON session_row.namespace=event_row.namespace "
|
|
605
|
-
"AND session_row.id=event_row.session_id "
|
|
606
|
-
f"WHERE {' AND '.join(clauses)} ORDER BY {order} "
|
|
607
|
-
f"LIMIT ${len(params)-1} OFFSET ${len(params)}",
|
|
608
|
-
*params,
|
|
609
|
-
)
|
|
610
|
-
events = [self._event_from_row(row) for row in rows]
|
|
611
|
-
if not query.from_start:
|
|
612
|
-
events.reverse()
|
|
613
|
-
return events
|
|
614
|
-
|
|
615
|
-
async def count_event_query(self, query: SessionEventQuery) -> int:
|
|
616
|
-
await self._ensure_schema()
|
|
617
|
-
clauses, params = self._batch_event_where(query)
|
|
618
|
-
async with self._pool.acquire() as connection:
|
|
619
|
-
return int(
|
|
620
|
-
await connection.fetchval(
|
|
621
|
-
f"SELECT COUNT(*) FROM {KSADK_PG_EVENTS_TABLE} event_row "
|
|
622
|
-
f"JOIN {KSADK_PG_SESSIONS_TABLE} session_row "
|
|
623
|
-
"ON session_row.namespace=event_row.namespace "
|
|
624
|
-
"AND session_row.id=event_row.session_id "
|
|
625
|
-
f"WHERE {' AND '.join(clauses)}",
|
|
626
|
-
*params,
|
|
627
|
-
)
|
|
628
|
-
or 0
|
|
629
|
-
)
|
|
630
|
-
|
|
631
|
-
async def scan_checkpoint_events(
|
|
632
|
-
self, query: CheckpointEventQuery
|
|
633
|
-
) -> list[SessionEvent]:
|
|
634
|
-
if query.limit < 1 or query.limit > 50:
|
|
635
|
-
raise ValueError("checkpoint scan limit must be between 1 and 50")
|
|
636
|
-
return await self._scan_checkpoint_events_with_connection(None, query)
|
|
637
|
-
|
|
638
|
-
async def _scan_checkpoint_events_with_connection(
|
|
639
|
-
self,
|
|
640
|
-
connection: Any | None,
|
|
641
|
-
query: CheckpointEventQuery,
|
|
642
|
-
cursor: tuple[float, str, int, str] | None = None,
|
|
643
|
-
) -> list[SessionEvent]:
|
|
644
|
-
event_query = SessionEventQuery(
|
|
645
|
-
session_ids=query.session_ids,
|
|
646
|
-
agent_id=query.agent_id,
|
|
647
|
-
event_types=["run_checkpoint", "continuation.created"],
|
|
648
|
-
offset=query.offset,
|
|
649
|
-
limit=query.limit,
|
|
650
|
-
from_start=True,
|
|
651
|
-
)
|
|
652
|
-
if query.framework is None and connection is None:
|
|
653
|
-
return await self.query_events(event_query)
|
|
654
|
-
await self._ensure_schema()
|
|
655
|
-
clauses, params = self._batch_event_where(event_query)
|
|
656
|
-
if query.checkpoint_ids:
|
|
657
|
-
params.append(query.checkpoint_ids)
|
|
658
|
-
clauses.append(
|
|
659
|
-
"(event_row.metadata_json->>'checkpoint_id'=ANY("
|
|
660
|
-
f"${len(params)}::text[])"
|
|
661
|
-
" OR (event_row.event_type='continuation.created'"
|
|
662
|
-
" AND event_row.content_json->'runtime_event'->>'continuation_id'=ANY("
|
|
663
|
-
f"${len(params)}::text[])))"
|
|
664
|
-
)
|
|
665
|
-
if query.run_id is not None:
|
|
666
|
-
params.append(query.run_id)
|
|
667
|
-
clauses.append(
|
|
668
|
-
"(event_row.metadata_json->>'run_id'="
|
|
669
|
-
f"${len(params)}"
|
|
670
|
-
" OR (event_row.event_type='continuation.created'"
|
|
671
|
-
f" AND event_row.content_json->'runtime_event'->>'run_id'=${len(params)}))"
|
|
672
|
-
)
|
|
673
|
-
if query.framework is not None:
|
|
674
|
-
params.append(query.framework.lower())
|
|
675
|
-
clauses.append(
|
|
676
|
-
"(lower(event_row.metadata_json->>'framework')="
|
|
677
|
-
f"${len(params)}"
|
|
678
|
-
" OR (event_row.event_type='continuation.created'"
|
|
679
|
-
" AND lower(event_row.content_json->'runtime_event'->'source'->>'framework')="
|
|
680
|
-
f"${len(params)}))"
|
|
681
|
-
)
|
|
682
|
-
if cursor is not None:
|
|
683
|
-
placeholders = []
|
|
684
|
-
for value in cursor:
|
|
685
|
-
params.append(value)
|
|
686
|
-
placeholders.append(f"${len(params)}")
|
|
687
|
-
clauses.append(
|
|
688
|
-
"(event_row.timestamp,event_row.session_id,event_row.seq_id,event_row.id) > "
|
|
689
|
-
f"({','.join(placeholders)})"
|
|
690
|
-
)
|
|
691
|
-
params.extend([query.limit, query.offset])
|
|
692
|
-
owns_connection = connection is None
|
|
693
|
-
if owns_connection:
|
|
694
|
-
connection = await self._pool.acquire()
|
|
695
|
-
try:
|
|
696
|
-
rows = await connection.fetch(
|
|
697
|
-
f"SELECT event_row.id,event_row.session_id,event_row.author,event_row.event_type,"
|
|
698
|
-
f"event_row.content_json,event_row.timestamp,event_row.state_delta_json,"
|
|
699
|
-
f"event_row.seq_id,event_row.invocation_id,event_row.metadata_json "
|
|
700
|
-
f"FROM {KSADK_PG_EVENTS_TABLE} event_row "
|
|
701
|
-
f"JOIN {KSADK_PG_SESSIONS_TABLE} session_row "
|
|
702
|
-
"ON session_row.namespace=event_row.namespace "
|
|
703
|
-
"AND session_row.id=event_row.session_id "
|
|
704
|
-
f"WHERE {' AND '.join(clauses)} ORDER BY event_row.timestamp,event_row.session_id,"
|
|
705
|
-
f"event_row.seq_id,event_row.id LIMIT ${len(params)-1} OFFSET ${len(params)}",
|
|
706
|
-
*params,
|
|
707
|
-
)
|
|
708
|
-
return [self._event_from_row(row) for row in rows]
|
|
709
|
-
finally:
|
|
710
|
-
if owns_connection:
|
|
711
|
-
await self._pool.release(connection)
|
|
712
|
-
|
|
713
|
-
async def iter_checkpoint_event_chunks(
|
|
714
|
-
self, query: CheckpointEventQuery
|
|
715
|
-
) -> AsyncIterator[list[SessionEvent]]:
|
|
716
|
-
if query.limit < 1 or query.limit > 50:
|
|
717
|
-
raise ValueError("checkpoint scan limit must be between 1 and 50")
|
|
718
|
-
await self._ensure_schema()
|
|
719
|
-
async with self._pool.acquire() as connection:
|
|
720
|
-
async with connection.transaction(isolation="repeatable_read", readonly=True):
|
|
721
|
-
token = self._checkpoint_snapshot_connection.set(connection)
|
|
722
|
-
try:
|
|
723
|
-
cursor: tuple[float, str, int, str] | None = None
|
|
724
|
-
first_page = True
|
|
725
|
-
while True:
|
|
726
|
-
batch = await self._scan_checkpoint_events_with_connection(
|
|
727
|
-
connection,
|
|
728
|
-
CheckpointEventQuery(
|
|
729
|
-
**{
|
|
730
|
-
**query.__dict__,
|
|
731
|
-
"offset": query.offset if first_page else 0,
|
|
732
|
-
}
|
|
733
|
-
),
|
|
734
|
-
cursor,
|
|
735
|
-
)
|
|
736
|
-
if not batch:
|
|
737
|
-
break
|
|
738
|
-
yield batch
|
|
739
|
-
if len(batch) < query.limit:
|
|
740
|
-
break
|
|
741
|
-
last = batch[-1]
|
|
742
|
-
cursor = (
|
|
743
|
-
last.timestamp,
|
|
744
|
-
last.session_id,
|
|
745
|
-
last.seq_id,
|
|
746
|
-
last.id,
|
|
747
|
-
)
|
|
748
|
-
first_page = False
|
|
749
|
-
finally:
|
|
750
|
-
self._checkpoint_snapshot_connection.reset(token)
|
|
751
|
-
|
|
752
|
-
async def get_checkpoint_lookup_stats(
|
|
753
|
-
self, session_id: str, run_id: str, checkpoint_id: str
|
|
754
|
-
) -> dict[str, object]:
|
|
755
|
-
events = await self.query_events(
|
|
756
|
-
SessionEventQuery(
|
|
757
|
-
session_ids=[session_id], run_id=run_id, limit=2**31 - 1, from_start=True
|
|
758
|
-
)
|
|
759
|
-
)
|
|
760
|
-
candidate = None
|
|
761
|
-
max_seq_id = 0
|
|
762
|
-
resume_count = 0
|
|
763
|
-
last_resumed_at = None
|
|
764
|
-
for event in events:
|
|
765
|
-
metadata = event.metadata or {}
|
|
766
|
-
if event.event_type == "run_checkpoint":
|
|
767
|
-
max_seq_id = max(max_seq_id, event.seq_id)
|
|
768
|
-
if str(metadata.get("checkpoint_id") or "") == checkpoint_id:
|
|
769
|
-
candidate = event
|
|
770
|
-
elif event.event_type == "run_resume" and str(
|
|
771
|
-
metadata.get("checkpoint_id") or ""
|
|
772
|
-
) == checkpoint_id:
|
|
773
|
-
resume_count += 1
|
|
774
|
-
last_resumed_at = max(last_resumed_at or event.timestamp, event.timestamp)
|
|
775
|
-
return {"candidate": candidate, "max_seq_id": max_seq_id, "resume_count": resume_count,
|
|
776
|
-
"last_resumed_at": last_resumed_at}
|
|
777
|
-
|
|
778
|
-
async def get_checkpoint_stats(
|
|
779
|
-
self, keys: list[tuple[str, str, str]]
|
|
780
|
-
) -> dict[str, object]:
|
|
781
|
-
if len(keys) > 50:
|
|
782
|
-
raise ValueError("checkpoint stats batch cannot exceed 50 keys")
|
|
783
|
-
unique_keys = list(dict.fromkeys(keys))
|
|
784
|
-
audits = {
|
|
785
|
-
key: {"resume_count": 0, "last_resumed_at": None} for key in unique_keys
|
|
786
|
-
}
|
|
787
|
-
run_keys = list(
|
|
788
|
-
dict.fromkeys((session_id, run_id) for session_id, run_id, _ in unique_keys)
|
|
789
|
-
)
|
|
790
|
-
latest = {key: 0 for key in run_keys}
|
|
791
|
-
if not unique_keys:
|
|
792
|
-
return {"audits": audits, "latest_seq_ids": latest}
|
|
793
|
-
await self._ensure_schema()
|
|
794
|
-
connection = self._checkpoint_snapshot_connection.get()
|
|
795
|
-
owns_connection = connection is None
|
|
796
|
-
if owns_connection:
|
|
797
|
-
connection = await self._pool.acquire()
|
|
798
|
-
try:
|
|
799
|
-
audit_rows = await connection.fetch(
|
|
800
|
-
f"""WITH requested(session_id,run_id,checkpoint_id) AS (
|
|
801
|
-
SELECT * FROM unnest($2::text[],$3::text[],$4::text[])
|
|
802
|
-
)
|
|
803
|
-
SELECT requested.session_id,requested.run_id,requested.checkpoint_id,
|
|
804
|
-
COUNT(event_row.id) AS resume_count,
|
|
805
|
-
MAX(event_row.timestamp) AS last_resumed_at
|
|
806
|
-
FROM requested
|
|
807
|
-
LEFT JOIN {KSADK_PG_EVENTS_TABLE} event_row
|
|
808
|
-
ON event_row.namespace=$1
|
|
809
|
-
AND event_row.session_id=requested.session_id
|
|
810
|
-
AND event_row.event_type='run_resume'
|
|
811
|
-
AND event_row.metadata_json->>'run_id'=requested.run_id
|
|
812
|
-
AND event_row.metadata_json->>'checkpoint_id'=requested.checkpoint_id
|
|
813
|
-
GROUP BY requested.session_id,requested.run_id,requested.checkpoint_id""",
|
|
814
|
-
self.namespace,
|
|
815
|
-
[key[0] for key in unique_keys],
|
|
816
|
-
[key[1] for key in unique_keys],
|
|
817
|
-
[key[2] for key in unique_keys],
|
|
818
|
-
)
|
|
819
|
-
latest_rows = await connection.fetch(
|
|
820
|
-
f"""WITH requested(session_id,run_id) AS (
|
|
821
|
-
SELECT * FROM unnest($2::text[],$3::text[])
|
|
822
|
-
)
|
|
823
|
-
SELECT requested.session_id,requested.run_id,
|
|
824
|
-
COALESCE(MAX(event_row.seq_id),0) AS latest_seq_id
|
|
825
|
-
FROM requested
|
|
826
|
-
LEFT JOIN {KSADK_PG_EVENTS_TABLE} event_row
|
|
827
|
-
ON event_row.namespace=$1
|
|
828
|
-
AND event_row.session_id=requested.session_id
|
|
829
|
-
AND event_row.event_type='run_checkpoint'
|
|
830
|
-
AND event_row.metadata_json->>'run_id'=requested.run_id
|
|
831
|
-
GROUP BY requested.session_id,requested.run_id""",
|
|
832
|
-
self.namespace,
|
|
833
|
-
[key[0] for key in run_keys],
|
|
834
|
-
[key[1] for key in run_keys],
|
|
835
|
-
)
|
|
836
|
-
finally:
|
|
837
|
-
if owns_connection:
|
|
838
|
-
await self._pool.release(connection)
|
|
839
|
-
for row in audit_rows:
|
|
840
|
-
audits[(row["session_id"], row["run_id"], row["checkpoint_id"])] = {
|
|
841
|
-
"resume_count": int(row["resume_count"] or 0),
|
|
842
|
-
"last_resumed_at": row["last_resumed_at"],
|
|
843
|
-
}
|
|
844
|
-
for row in latest_rows:
|
|
845
|
-
latest[(row["session_id"], row["run_id"])] = int(
|
|
846
|
-
row["latest_seq_id"] or 0
|
|
847
|
-
)
|
|
848
|
-
return {"audits": audits, "latest_seq_ids": latest}
|
|
849
|
-
|
|
850
|
-
def _agent_events_query_parts(
|
|
851
|
-
self,
|
|
852
|
-
agent_id: str,
|
|
853
|
-
user_id: Optional[str],
|
|
854
|
-
) -> tuple[str, list[Any]]:
|
|
855
|
-
"""跨会话事件查询的公共 JOIN/WHERE。events 表无 agent_id 列,需 join sessions。"""
|
|
856
|
-
conditions = [
|
|
857
|
-
"e.namespace = $1",
|
|
858
|
-
"s.namespace = e.namespace",
|
|
859
|
-
"s.id = e.session_id",
|
|
860
|
-
"s.agent_id = $2",
|
|
861
|
-
]
|
|
862
|
-
params: list[Any] = [self.namespace, agent_id]
|
|
863
|
-
if user_id is not None:
|
|
864
|
-
params.append(user_id)
|
|
865
|
-
conditions.append(f"s.user_id = ${len(params)}")
|
|
866
|
-
where_clause = " AND ".join(conditions)
|
|
867
|
-
from_clause = (
|
|
868
|
-
f"FROM {KSADK_PG_EVENTS_TABLE} e "
|
|
869
|
-
f"JOIN {KSADK_PG_SESSIONS_TABLE} s "
|
|
870
|
-
"ON s.namespace = e.namespace AND s.id = e.session_id "
|
|
871
|
-
f"WHERE {where_clause}"
|
|
872
|
-
)
|
|
873
|
-
return from_clause, params
|
|
874
|
-
|
|
875
|
-
async def get_events_for_agent(
|
|
876
|
-
self,
|
|
877
|
-
agent_id: str,
|
|
878
|
-
user_id: Optional[str] = None,
|
|
879
|
-
offset: Optional[int] = None,
|
|
880
|
-
limit: Optional[int] = None,
|
|
881
|
-
) -> list[SessionEvent]:
|
|
882
|
-
await self._ensure_schema()
|
|
883
|
-
from_clause, params = self._agent_events_query_parts(agent_id, user_id)
|
|
884
|
-
columns = (
|
|
885
|
-
"e.id, e.session_id, e.author, e.event_type, e.content_json, e.timestamp, "
|
|
886
|
-
"e.state_delta_json, e.seq_id, e.invocation_id, e.metadata_json"
|
|
887
|
-
)
|
|
888
|
-
async with self._pool.acquire() as connection:
|
|
889
|
-
if limit is not None or offset is not None:
|
|
890
|
-
# 与 get_events 一致的"最新 N 条"尾部语义:先 DESC 取窗口再 ASC 重排
|
|
891
|
-
if limit is not None:
|
|
892
|
-
params.append(limit)
|
|
893
|
-
limit_sql = f"LIMIT ${len(params)}"
|
|
894
|
-
else:
|
|
895
|
-
limit_sql = ""
|
|
896
|
-
params.append(offset or 0)
|
|
897
|
-
offset_sql = f"OFFSET ${len(params)}"
|
|
898
|
-
query = f"""
|
|
899
|
-
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
900
|
-
state_delta_json, seq_id, invocation_id, metadata_json
|
|
901
|
-
FROM (
|
|
902
|
-
SELECT {columns}
|
|
903
|
-
{from_clause}
|
|
904
|
-
ORDER BY e.timestamp DESC, e.seq_id DESC, e.id DESC
|
|
905
|
-
{limit_sql} {offset_sql}
|
|
906
|
-
) AS latest_events
|
|
907
|
-
ORDER BY timestamp ASC, seq_id ASC, id ASC
|
|
908
|
-
"""
|
|
909
|
-
else:
|
|
910
|
-
query = f"""
|
|
911
|
-
SELECT {columns}
|
|
912
|
-
{from_clause}
|
|
913
|
-
ORDER BY e.timestamp ASC, e.seq_id ASC, e.id ASC
|
|
914
|
-
"""
|
|
915
|
-
rows = await connection.fetch(query, *params)
|
|
916
|
-
return [self._event_from_row(row) for row in rows]
|
|
917
|
-
|
|
918
|
-
async def count_events_for_agent(
|
|
919
|
-
self,
|
|
920
|
-
agent_id: str,
|
|
921
|
-
user_id: Optional[str] = None,
|
|
922
|
-
) -> int:
|
|
923
|
-
await self._ensure_schema()
|
|
924
|
-
from_clause, params = self._agent_events_query_parts(agent_id, user_id)
|
|
925
|
-
async with self._pool.acquire() as connection:
|
|
926
|
-
query = f"SELECT COUNT(*) AS total {from_clause}"
|
|
927
|
-
return int(await connection.fetchval(query, *params) or 0)
|
|
888
|
+
@_write_deadline
|
|
889
|
+
async def settle_tool_receipt(self, session_id: str, **kwargs):
|
|
890
|
+
return await super().settle_tool_receipt(session_id, **kwargs)
|
|
928
891
|
|
|
929
892
|
async def get_state(
|
|
930
893
|
self,
|
|
@@ -934,9 +897,11 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
934
897
|
scope: str = "session",
|
|
935
898
|
) -> Optional[SessionState]:
|
|
936
899
|
await self._ensure_schema()
|
|
937
|
-
async with self.
|
|
900
|
+
async with self._connection() as connection:
|
|
938
901
|
if scope == "session" and session_id:
|
|
939
|
-
session = await self._get_session_with_connection(
|
|
902
|
+
session = await self._get_session_with_connection(
|
|
903
|
+
connection, session_id, include_events=False
|
|
904
|
+
)
|
|
940
905
|
if session is None:
|
|
941
906
|
return None
|
|
942
907
|
return SessionState(
|
|
@@ -965,6 +930,7 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
965
930
|
return None
|
|
966
931
|
return self._state_from_row(row)
|
|
967
932
|
|
|
933
|
+
@_write_deadline
|
|
968
934
|
async def update_state(
|
|
969
935
|
self,
|
|
970
936
|
*,
|
|
@@ -975,8 +941,9 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
975
941
|
state_delta: dict[str, Any],
|
|
976
942
|
) -> SessionState:
|
|
977
943
|
await self._ensure_schema()
|
|
978
|
-
async with self.
|
|
944
|
+
async with self._connection(write=True) as connection:
|
|
979
945
|
async with connection.transaction():
|
|
946
|
+
await self._set_lock_timeout(connection)
|
|
980
947
|
updated_at = time.time()
|
|
981
948
|
if scope == "session":
|
|
982
949
|
if not session_id:
|
|
@@ -1089,7 +1056,7 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
1089
1056
|
min_size=self.min_size,
|
|
1090
1057
|
max_size=self.max_size,
|
|
1091
1058
|
timeout=self.connect_timeout,
|
|
1092
|
-
command_timeout=self.
|
|
1059
|
+
command_timeout=self.db_budget.write_sql_seconds,
|
|
1093
1060
|
)
|
|
1094
1061
|
except (TimeoutError, OSError, ConnectionError, asyncio.TimeoutError) as exc:
|
|
1095
1062
|
raise SessionBackendUnavailable(
|
|
@@ -1129,7 +1096,7 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
1129
1096
|
async def _get_events_with_connection(
|
|
1130
1097
|
self, connection: Any, session_id: str
|
|
1131
1098
|
) -> list[SessionEvent]:
|
|
1132
|
-
rows = await connection.fetch(
|
|
1099
|
+
rows = await getattr(connection, "fetch_replay", connection.fetch)(
|
|
1133
1100
|
f"""
|
|
1134
1101
|
SELECT id, session_id, author, event_type, content_json, timestamp,
|
|
1135
1102
|
state_delta_json, seq_id, invocation_id, metadata_json
|
|
@@ -1243,7 +1210,6 @@ class PostgresSessionService(_PostgresSchemaMixin, BaseSessionService):
|
|
|
1243
1210
|
return dict(json.loads(value or "{}"))
|
|
1244
1211
|
return dict(value)
|
|
1245
1212
|
|
|
1246
|
-
|
|
1247
1213
|
def create_postgres_session_service(
|
|
1248
1214
|
*,
|
|
1249
1215
|
dsn: str,
|