agentengine-sdk-python 0.7.0__py3-none-any.whl → 0.8.1__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.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/METADATA +52 -20
- agentengine_sdk_python-0.8.1.dist-info/RECORD +644 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/WHEEL +1 -1
- ksadk/a2a/__init__.py +180 -11
- ksadk/a2a/bootstrap.py +332 -0
- ksadk/a2a/card.py +15 -0
- ksadk/a2a/context_store.py +203 -0
- ksadk/a2a/control_plane.py +1056 -0
- ksadk/a2a/credential.py +99 -0
- ksadk/a2a/event_adapter.py +149 -0
- ksadk/a2a/executor.py +361 -137
- ksadk/a2a/external_transport.py +516 -0
- ksadk/a2a/identity.py +304 -0
- ksadk/a2a/ids.py +22 -0
- ksadk/a2a/langgraph.py +285 -0
- ksadk/a2a/resume_store.py +201 -0
- ksadk/a2a/routes.py +112 -0
- ksadk/a2a/server.py +102 -62
- ksadk/a2a/service_env.py +33 -0
- ksadk/a2a/space_client.py +1122 -0
- ksadk/a2a/task_adapter.py +423 -0
- ksadk/a2a/task_event_dispatcher.py +167 -0
- ksadk/a2a/task_event_outbox.py +326 -0
- ksadk/a2a/task_store.py +206 -0
- ksadk/a2a_card.py +101 -0
- ksadk/a2ui/__init__.py +27 -0
- ksadk/a2ui/core.py +186 -0
- ksadk/a2ui/models.py +166 -0
- ksadk/a2ui/renderer.py +198 -0
- ksadk/agui/__init__.py +9 -0
- ksadk/agui/a2ui_projection.py +92 -0
- ksadk/agui/agent.py +872 -0
- ksadk/agui/config.py +92 -0
- ksadk/agui/routes.py +47 -0
- ksadk/api/client.py +238 -204
- ksadk/api/environment.py +27 -0
- ksadk/builders/__init__.py +2 -0
- ksadk/builders/base.py +16 -14
- ksadk/builders/code_builder.py +375 -270
- ksadk/builders/container_builder.py +240 -200
- ksadk/builders/framework_requirements.py +31 -12
- ksadk/builders/ks3_uploader.py +60 -29
- ksadk/builders/managed_runtime_builder.py +173 -0
- ksadk/builders/mcp_builder.py +91 -92
- ksadk/builders/requirements_utils.py +1 -5
- ksadk/cli/__init__.py +97 -171
- ksadk/cli/cmd_a2a.py +255 -84
- ksadk/cli/cmd_agent.py +19 -5
- ksadk/cli/cmd_build.py +158 -29
- ksadk/cli/cmd_completion.py +47 -35
- ksadk/cli/cmd_config.py +267 -198
- ksadk/cli/cmd_create.py +507 -740
- ksadk/cli/cmd_dashboard.py +120 -45
- ksadk/cli/cmd_deploy.py +135 -59
- ksadk/cli/cmd_destroy.py +44 -14
- ksadk/cli/cmd_eval.py +386 -0
- ksadk/cli/cmd_files.py +63 -24
- ksadk/cli/cmd_hermes.py +313 -135
- ksadk/cli/cmd_invoke.py +184 -122
- ksadk/cli/cmd_launch.py +76 -28
- ksadk/cli/cmd_mcp.py +98 -64
- ksadk/cli/cmd_model.py +14 -5
- ksadk/cli/cmd_openclaw.py +564 -268
- ksadk/cli/cmd_replay.py +71 -0
- ksadk/cli/cmd_run.py +58 -73
- ksadk/cli/cmd_status.py +80 -31
- ksadk/cli/cmd_studio.py +110 -0
- ksadk/cli/cmd_version.py +20 -13
- ksadk/cli/cmd_web.py +95 -18
- ksadk/cli/deploy_utils.py +20 -20
- ksadk/cli/dry_run.py +7 -4
- ksadk/cli/env_options.py +83 -0
- ksadk/cli/error_utils.py +37 -12
- ksadk/cli/global_options.py +4 -3
- ksadk/cli/local_runtime.py +1 -2
- ksadk/cli/model_catalog.py +6 -2
- ksadk/cli/network_options.py +41 -19
- ksadk/cli/resource_common.py +6 -2
- ksadk/cli/runtime_bootstrap.py +51 -0
- ksadk/cli/storage.py +0 -1
- ksadk/cli/ui.py +11 -3
- ksadk/cli/workflow_common.py +52 -18
- ksadk/codex/__init__.py +12 -0
- ksadk/codex/client.py +1042 -0
- ksadk/codex/phase.py +143 -0
- ksadk/codex/runtime.py +940 -0
- ksadk/common/aicp_env.py +0 -1
- ksadk/common/auth.py +2 -2
- ksadk/common/constants.py +1 -3
- ksadk/common/kop_client.py +232 -0
- ksadk/common/llm_utils.py +17 -13
- ksadk/compat/__init__.py +5 -0
- ksadk/compat/adk_compat.py +200 -0
- ksadk/compat/copilotkit_a2ui.py +330 -0
- ksadk/configs/__init__.py +12 -14
- ksadk/configs/env_registry.py +661 -116
- ksadk/configs/global_config.py +3 -2
- ksadk/configs/settings.py +133 -209
- ksadk/conversations/__init__.py +85 -92
- ksadk/conversations/attachment_storage.py +16 -11
- ksadk/conversations/attachments.py +44 -36
- ksadk/conversations/compaction_pipeline.py +12 -12
- ksadk/conversations/compaction_prompt.py +9 -5
- ksadk/conversations/context.py +221 -6
- ksadk/conversations/message_projection.py +438 -51
- ksadk/conversations/model_context.py +12 -6
- ksadk/conversations/model_options.py +0 -1
- ksadk/conversations/normalize.py +20 -16
- ksadk/conversations/reasoning_markup.py +1 -1
- ksadk/conversations/runtime.py +339 -5255
- ksadk/conversations/runtime_compaction.py +333 -0
- ksadk/conversations/runtime_constants.py +27 -0
- ksadk/conversations/runtime_governance.py +185 -0
- ksadk/conversations/runtime_input.py +660 -0
- ksadk/conversations/runtime_invocation.py +395 -0
- ksadk/conversations/runtime_metadata.py +475 -0
- ksadk/conversations/runtime_observability.py +367 -0
- ksadk/conversations/runtime_payloads.py +272 -0
- ksadk/conversations/runtime_persistence.py +440 -0
- ksadk/conversations/runtime_preparation.py +426 -0
- ksadk/conversations/runtime_resume.py +836 -0
- ksadk/conversations/runtime_stream_events.py +902 -0
- ksadk/conversations/runtime_streaming.py +700 -0
- ksadk/conversations/semantic_summary.py +17 -5
- ksadk/conversations/session_title.py +6 -3
- ksadk/deployment/__init__.py +15 -16
- ksadk/deployment/agent_access.py +12 -23
- ksadk/deployment/base.py +51 -38
- ksadk/deployment/managed_runtime.py +33 -0
- ksadk/deployment/manager.py +85 -71
- ksadk/deployment/providers/serverless.py +379 -210
- ksadk/deployment/registry.py +38 -32
- ksadk/deployment/state.py +11 -11
- ksadk/deployment/ui_config.py +1 -1
- ksadk/detection/__init__.py +1 -1
- ksadk/detection/detector.py +146 -83
- ksadk/detection/mcp_detector.py +9 -6
- ksadk/evaluation/__init__.py +84 -0
- ksadk/evaluation/a2a_adapter.py +444 -0
- ksadk/evaluation/adapters.py +54 -0
- ksadk/evaluation/contracts.py +409 -0
- ksadk/evaluation/evalset.py +351 -0
- ksadk/evaluation/evaluators.py +461 -0
- ksadk/evaluation/executor.py +118 -0
- ksadk/evaluation/storage.py +68 -0
- ksadk/evaluation/target.py +73 -0
- ksadk/events/__init__.py +25 -0
- ksadk/events/parser.py +191 -0
- ksadk/events/replay.py +37 -0
- ksadk/events/runtime_event.py +273 -0
- ksadk/events/store.py +317 -0
- ksadk/harness/__init__.py +35 -0
- ksadk/harness/app.py +269 -0
- ksadk/harness/config.py +181 -0
- ksadk/harness/reasoner.py +105 -0
- ksadk/harness/runtime.py +364 -0
- ksadk/harness/sandbox.py +141 -0
- ksadk/harness/tools.py +222 -0
- ksadk/hermes_terminal.py +28 -12
- ksadk/identity/resolver.py +15 -9
- ksadk/ids.py +32 -0
- ksadk/knowledge_base/adk_tool.py +1 -1
- ksadk/knowledge_base/client.py +38 -33
- ksadk/managed_a2a_card.py +160 -0
- ksadk/managed_runtime.py +195 -0
- ksadk/markdown.py +5 -2
- ksadk/mcp_runtime/__init__.py +9 -6
- ksadk/memory/__init__.py +1 -1
- ksadk/memory/adk/__init__.py +2 -0
- ksadk/memory/adk/backends/base_ltm_backend.py +2 -6
- ksadk/memory/adk/backends/http_ltm_backend.py +13 -21
- ksadk/memory/adk/backends/inmemory_ltm_backend.py +7 -13
- ksadk/memory/adk/backends/sdk_ltm_backend.py +36 -36
- ksadk/memory/adk/long_term_memory.py +34 -37
- ksadk/memory/adk/resilient_session_service.py +4 -5
- ksadk/memory/adk/short_term_memory.py +12 -21
- ksadk/memory/adk_tool.py +3 -2
- ksadk/memory/backends/base.py +19 -19
- ksadk/memory/backends/memory.py +24 -25
- ksadk/memory/backends/redis.py +31 -30
- ksadk/memory/langchain_tool.py +2 -1
- ksadk/memory/manager.py +52 -47
- ksadk/memory/service.py +16 -6
- ksadk/memory/tool.py +4 -0
- ksadk/model_policy.py +15 -7
- ksadk/model_proxy/__init__.py +51 -0
- ksadk/model_proxy/bootstrap.py +80 -0
- ksadk/model_proxy/cache.py +165 -0
- ksadk/model_proxy/config.py +66 -0
- ksadk/model_proxy/demo_webui.py +115 -0
- ksadk/model_proxy/detect.py +145 -0
- ksadk/model_proxy/gate.py +68 -0
- ksadk/model_proxy/namespace.py +201 -0
- ksadk/model_proxy/protocol_proxy.py +22 -0
- ksadk/model_proxy/server.py +443 -0
- ksadk/model_proxy/transform.py +735 -0
- ksadk/openclaw_gateway.py +29 -14
- ksadk/runners/adk_runner.py +354 -146
- ksadk/runners/base_runner.py +71 -29
- ksadk/runners/deepagents_runner.py +0 -1
- ksadk/runners/factory.py +18 -5
- ksadk/runners/langchain_runner.py +29 -742
- ksadk/runners/langgraph_runner.py +417 -97
- ksadk/runners/patch_langchain.py +16 -16
- ksadk/runners/remote_runner.py +134 -33
- ksadk/runners/usage_accumulator.py +1 -0
- ksadk/runners/utils/__init__.py +0 -10
- ksadk/runners/utils/loader.py +23 -7
- ksadk/runtime/__init__.py +67 -0
- ksadk/runtime/adapter.py +412 -0
- ksadk/runtime/conversation_execution.py +553 -0
- ksadk/runtime/executor.py +251 -0
- ksadk/runtime/factory.py +156 -0
- ksadk/runtime/framework_adapters.py +118 -0
- ksadk/runtime/launch.py +48 -0
- ksadk/runtime/preprocessing.py +131 -0
- ksadk/runtime/runner_adapter.py +1032 -0
- ksadk/runtime/runner_loading.py +36 -0
- ksadk/runtime_context.py +18 -3
- ksadk/runtime_state.py +0 -1
- ksadk/sandbox/__init__.py +4 -1
- ksadk/sandbox/backends/__init__.py +4 -1
- ksadk/sandbox/backends/e2b.py +13 -5
- ksadk/sandbox/backends/local_process.py +11 -3
- ksadk/sandbox/base.py +10 -15
- ksadk/sandbox/factory.py +14 -4
- ksadk/sandbox/registry.py +57 -6
- ksadk/server/__init__.py +39 -4
- ksadk/server/api_models.py +15 -5
- ksadk/server/app.py +24 -3928
- ksadk/server/composition.py +47 -0
- ksadk/server/factory.py +622 -0
- ksadk/server/routes/__init__.py +1 -0
- ksadk/server/routes/checkpoint_resolution.py +116 -0
- ksadk/server/routes/common.py +682 -0
- ksadk/server/routes/control.py +331 -0
- ksadk/server/routes/dependencies.py +98 -0
- ksadk/server/routes/misc.py +425 -0
- ksadk/server/routes/models.py +451 -0
- ksadk/server/routes/openai_compat.py +229 -0
- ksadk/server/routes/projection.py +848 -0
- ksadk/server/routes/routers.py +52 -0
- ksadk/server/routes/run.py +519 -0
- ksadk/server/routes/sessions.py +644 -0
- ksadk/server/routes/streaming.py +265 -0
- ksadk/server/routes/workspace.py +414 -0
- ksadk/server/static/assets/{ArtifactsPanel-D-SSn2ee.js → ArtifactsPanel-CakCqxEN.js} +1 -1
- ksadk/server/static/assets/CodeBlock-CynLknyO.js +9 -0
- ksadk/server/static/assets/MathMessageMarkdown-3sQdOysS.js +8 -0
- ksadk/server/static/assets/MermaidBlock-NERD_ef7.js +303 -0
- ksadk/server/static/assets/NativeTerminalPanel-CiHWf82q.js +1 -0
- ksadk/server/static/assets/{arc-BA13sHc9.js → arc-DrgjcKhl.js} +1 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-CpZLRCcY.js +1 -0
- ksadk/server/static/assets/{architectureDiagram-3BPJPVTR-DzJzgVoL.js → architectureDiagram-3BPJPVTR-BXoVRbQ6.js} +1 -1
- ksadk/server/static/assets/{blockDiagram-GPEHLZMM-UTdVcZhn.js → blockDiagram-GPEHLZMM-BnaB3Ywv.js} +1 -1
- ksadk/server/static/assets/{c4Diagram-AAUBKEIU-Dix0GD4m.js → c4Diagram-AAUBKEIU-Dw4weZcp.js} +1 -1
- ksadk/server/static/assets/channel-Dt3rQTFI.js +1 -0
- ksadk/server/static/assets/{chunk-2J33WTMH-C2JxuZ42.js → chunk-2J33WTMH-ChjpLK7j.js} +1 -1
- ksadk/server/static/assets/{chunk-4BX2VUAB-Be57QPgD.js → chunk-4BX2VUAB-B9drTgOW.js} +1 -1
- ksadk/server/static/assets/{chunk-55IACEB6-WjSuy4nv.js → chunk-55IACEB6-CK4ROATy.js} +1 -1
- ksadk/server/static/assets/{chunk-727SXJPM-BOovP-b5.js → chunk-727SXJPM-B9KtTTgw.js} +1 -1
- ksadk/server/static/assets/{chunk-AQP2D5EJ-DOmZNmWj.js → chunk-AQP2D5EJ-1O1mki3m.js} +1 -1
- ksadk/server/static/assets/{chunk-FMBD7UC4-DzwlodkU.js → chunk-FMBD7UC4-B_fH2YuH.js} +1 -1
- ksadk/server/static/assets/{chunk-ND2GUHAM-DMqAikEU.js → chunk-ND2GUHAM-D6rFLaVV.js} +1 -1
- ksadk/server/static/assets/chunk-QZHKN3VN-iXEZtKQc.js +1 -0
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-DIveV17Q.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-DIveV17Q.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-S5V4N54A-Zhy2GBnP.js → cose-bilkent-S5V4N54A-ChNs_Mdk.js} +1 -1
- ksadk/server/static/assets/{dagre-BM42HDAG-CbKrtIUz.js → dagre-BM42HDAG-D0QXg_MQ.js} +1 -1
- ksadk/server/static/assets/{diagram-2AECGRRQ-BRApgQRK.js → diagram-2AECGRRQ-DBDDKwBQ.js} +1 -1
- ksadk/server/static/assets/{diagram-5GNKFQAL-D0xbnDiK.js → diagram-5GNKFQAL-BkwDOxmO.js} +1 -1
- ksadk/server/static/assets/{diagram-KO2AKTUF-CVugVI9L.js → diagram-KO2AKTUF-Bv8waYvY.js} +1 -1
- ksadk/server/static/assets/{diagram-LMA3HP47-DozUGgee.js → diagram-LMA3HP47-e1VECDdu.js} +1 -1
- ksadk/server/static/assets/{diagram-OG6HWLK6-ZOYsKlru.js → diagram-OG6HWLK6-Ds9adfRl.js} +1 -1
- ksadk/server/static/assets/{dist-DpKtt4Bo.js → dist-4N2NMVYg.js} +1 -1
- ksadk/server/static/assets/{dist-CkEKJFtk.js → dist-B-jNR6Vn.js} +1 -1
- ksadk/server/static/assets/{dist-D57wnGWd.js → dist-B5J2uhNk.js} +1 -1
- ksadk/server/static/assets/{dist-8_SfK1IP.js → dist-B5oS1zcj.js} +1 -1
- ksadk/server/static/assets/{dist-DMezvBGJ.js → dist-BB3-OwTQ.js} +1 -1
- ksadk/server/static/assets/{dist-2hInLS_J.js → dist-BIlKoW0k.js} +1 -1
- ksadk/server/static/assets/{dist-BrCcQ47T.js → dist-BjOdlDjj.js} +1 -1
- ksadk/server/static/assets/{dist-BmlMPsCc.js → dist-C1sz5Eo3.js} +1 -1
- ksadk/server/static/assets/{dist-B0NP_Z0z.js → dist-CWV4lDr1.js} +1 -1
- ksadk/server/static/assets/{dist-D-xOD048.js → dist-CmZHzlwZ.js} +1 -1
- ksadk/server/static/assets/{dist-DL_NKc_z.js → dist-D6MpCZtz.js} +1 -1
- ksadk/server/static/assets/{dist-DyOkZmze.js → dist-DJN_6Y39.js} +1 -1
- ksadk/server/static/assets/{dist-DmFaq_Iy.js → dist-DQU9EWw-.js} +1 -1
- ksadk/server/static/assets/{dist-gX6GOLKq.js → dist-DWKByxWV.js} +1 -1
- ksadk/server/static/assets/{dist-DyWsb78Q.js → dist-Dli7qW-B.js} +1 -1
- ksadk/server/static/assets/{dist-BIJVDMuB.js → dist-DsHPdk3W.js} +1 -1
- ksadk/server/static/assets/{dist-Dp0k7bWI.js → dist-X4TnqwOK.js} +1 -1
- ksadk/server/static/assets/{dist-8EEyGgDx.js → dist-_pHPTyZ-.js} +1 -1
- ksadk/server/static/assets/{dist-CPBtqRTW.js → dist-fhOuWds5.js} +1 -1
- ksadk/server/static/assets/{dist-D-JMdWPQ.js → dist-gLnrGsoU.js} +1 -1
- ksadk/server/static/assets/{dist-BssVmjIo.js → dist-j6Dxmf_j.js} +1 -1
- ksadk/server/static/assets/{dist-C3HIIaN5.js → dist-o2OVmKvt.js} +1 -1
- ksadk/server/static/assets/{erDiagram-TEJ5UH35-Bk-9bgE5.js → erDiagram-TEJ5UH35-BPItFKH6.js} +1 -1
- ksadk/server/static/assets/eventmodeling-FCH6USID-DYFSxbqr.js +1 -0
- ksadk/server/static/assets/{flowDiagram-I6XJVG4X-Dn9kZVuZ.js → flowDiagram-I6XJVG4X-BbYB9w5Y.js} +1 -1
- ksadk/server/static/assets/{ganttDiagram-6RSMTGT7-BGxXlJqm.js → ganttDiagram-6RSMTGT7-TQXa0KXv.js} +1 -1
- ksadk/server/static/assets/gitGraph-WXDBUCRP-DyNYp6BN.js +1 -0
- ksadk/server/static/assets/{gitGraphDiagram-PVQCEYII-C7Q0X-wi.js → gitGraphDiagram-PVQCEYII-bKblCnpa.js} +1 -1
- ksadk/server/static/assets/index-R52pJJvg.js +177 -0
- ksadk/server/static/assets/index-jJr3_955.css +2 -0
- ksadk/server/static/assets/info-J43DQDTF-WUx7qTde.js +1 -0
- ksadk/server/static/assets/{infoDiagram-5YYISTIA-BO_CSqq5.js → infoDiagram-5YYISTIA-BGVT7J_i.js} +1 -1
- ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-eYLPLd46.js → ishikawaDiagram-YF4QCWOH-K0OOfVna.js} +1 -1
- ksadk/server/static/assets/{journeyDiagram-JHISSGLW-De9geSb0.js → journeyDiagram-JHISSGLW-8LeOJaZp.js} +1 -1
- ksadk/server/static/assets/{kanban-definition-UN3LZRKU-Cs80kQto.js → kanban-definition-UN3LZRKU-C6uCgZrW.js} +1 -1
- ksadk/server/static/assets/{katex-DSrCFD8n.js → katex-CYWseY5E.js} +1 -1
- ksadk/server/static/assets/{linear-CN9sbKTF.js → linear-hdBcYzM8.js} +1 -1
- ksadk/server/static/assets/{mermaid-parser.core-DlgSBU8l.js → mermaid-parser.core-BWrDjSZM.js} +2 -2
- ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-9afz7Oug.js → mindmap-definition-RKZ34NQL-Bjy_2v4_.js} +1 -1
- ksadk/server/static/assets/packet-YPE3B663-BN13y_xl.js +1 -0
- ksadk/server/static/assets/pie-LRSECV5Y-ftSLXhhc.js +1 -0
- ksadk/server/static/assets/{pieDiagram-4H26LBE5-DPv_VstN.js → pieDiagram-4H26LBE5-GmmqNiVH.js} +1 -1
- ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-o77wZ1XK.js → quadrantDiagram-W4KKPZXB-BmkRbwCg.js} +1 -1
- ksadk/server/static/assets/radar-GUYGQ44K-jaICkIeO.js +1 -0
- ksadk/server/static/assets/{requirementDiagram-4Y6WPE33-BYVw81VC.js → requirementDiagram-4Y6WPE33-DSWFqL7c.js} +1 -1
- ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-B7nZFMKT.js → sankeyDiagram-5OEKKPKP-l6iXmU65.js} +1 -1
- ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-BGRRrFw5.js → sequenceDiagram-3UESZ5HK-Cq6UBeQB.js} +1 -1
- ksadk/server/static/assets/{stateDiagram-AJRCARHV-BUfHCoPs.js → stateDiagram-AJRCARHV-qzTQpg3Y.js} +1 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-BYCoYGAN.js +1 -0
- ksadk/server/static/assets/{timeline-definition-PNZ67QCA-FbCTGrf9.js → timeline-definition-PNZ67QCA-DEz24vV0.js} +1 -1
- ksadk/server/static/assets/treeView-BLDUP644-Cpib_vlz.js +1 -0
- ksadk/server/static/assets/treemap-LRROVOQU-DQxfmVHK.js +1 -0
- ksadk/server/static/assets/{vennDiagram-CIIHVFJN-DWgwtPsJ.js → vennDiagram-CIIHVFJN-CMCixki2.js} +1 -1
- ksadk/server/static/assets/wardley-L42UT6IY-BQYHnnkU.js +1 -0
- ksadk/server/static/assets/{wardleyDiagram-YWT4CUSO-2x8G-tTM.js → wardleyDiagram-YWT4CUSO-CVzB8F9K.js} +1 -1
- ksadk/server/static/assets/{xychartDiagram-2RQKCTM6-Drma3AYl.js → xychartDiagram-2RQKCTM6-BFBqBLc1.js} +1 -1
- ksadk/server/static/index.html +2 -2
- ksadk/server/terminal_sessions.py +111 -58
- ksadk/sessions/__init__.py +69 -19
- ksadk/sessions/base.py +31 -11
- ksadk/sessions/continuity.py +2 -3
- ksadk/sessions/in_memory.py +46 -2
- ksadk/sessions/local_service.py +148 -17
- ksadk/sessions/postgres_service.py +143 -25
- ksadk/sessions/resilient.py +36 -8
- ksadk/skills/models.py +17 -5
- ksadk/skills/package_store.py +5 -2
- ksadk/skills/runtime/agent.py +20 -5
- ksadk/skills/runtime/artifacts.py +1 -5
- ksadk/skills/runtime/backends/e2b.py +10 -4
- ksadk/skills/runtime/backends/local.py +15 -3
- ksadk/skills/runtime/base.py +1 -2
- ksadk/skills/runtime/executor.py +10 -3
- ksadk/skills/runtime/factory.py +4 -2
- ksadk/skills/runtime/loader.py +1 -2
- ksadk/skills/runtime/registry.py +15 -10
- ksadk/skills/runtime/request.py +3 -1
- ksadk/skills/service_client.py +47 -16
- ksadk/skills/tool_defs.py +15 -10
- ksadk/studio/__init__.py +5 -0
- ksadk/studio/agent_avatar_assets.py +120 -0
- ksadk/studio/agent_lifecycle.py +51 -0
- ksadk/studio/api.py +1046 -0
- ksadk/studio/api_catalog_routes.py +324 -0
- ksadk/studio/api_contracts.py +177 -0
- ksadk/studio/api_helpers.py +132 -0
- ksadk/studio/authoring.py +524 -0
- ksadk/studio/authoring_coordinator.py +285 -0
- ksadk/studio/builder.py +320 -0
- ksadk/studio/capabilities.py +351 -0
- ksadk/studio/cloud.py +278 -0
- ksadk/studio/codex_agent_service.py +583 -0
- ksadk/studio/codex_builder.py +324 -0
- ksadk/studio/codex_manifest.py +278 -0
- ksadk/studio/codex_run.py +352 -0
- ksadk/studio/compiler.py +189 -0
- ksadk/studio/contracts.py +644 -0
- ksadk/studio/errors.py +47 -0
- ksadk/studio/evaluation.py +192 -0
- ksadk/studio/event_store.py +284 -0
- ksadk/studio/framework_run.py +114 -0
- ksadk/studio/identifiers.py +33 -0
- ksadk/studio/mcp_runtime.py +229 -0
- ksadk/studio/model_client.py +543 -0
- ksadk/studio/model_profile_service.py +214 -0
- ksadk/studio/operations.py +243 -0
- ksadk/studio/otel_trace.py +754 -0
- ksadk/studio/pagination.py +182 -0
- ksadk/studio/python_tool_inspection.py +183 -0
- ksadk/studio/repository.py +306 -0
- ksadk/studio/resource_catalog.py +1217 -0
- ksadk/studio/run_service.py +707 -0
- ksadk/studio/runtime_catalog.py +74 -0
- ksadk/studio/runtime_source.py +339 -0
- ksadk/studio/service.py +1141 -0
- ksadk/studio/shared_web.py +994 -0
- ksadk/studio/skill_discovery.py +628 -0
- ksadk/studio/static/assets/PrismRenderer-IYN-ffww.js +3 -0
- ksadk/studio/static/assets/index-CaEN0eTR.css +1 -0
- ksadk/studio/static/assets/index-DI2eY_NH.js +252 -0
- ksadk/studio/static/assets/react-vendor-BNmTiJ-I.js +9 -0
- ksadk/studio/static/assets/rolldown-runtime-hePW80VL.js +1 -0
- ksadk/studio/static/index.html +15 -0
- ksadk/studio/templates.py +630 -0
- ksadk/studio/validator.py +246 -0
- ksadk/studio/workspace.py +137 -0
- ksadk/terminal_exec_policy.py +3 -4
- ksadk/tools/gateway.py +101 -15
- ksadk/tools/result_budget.py +12 -4
- ksadk/toolsets/__init__.py +161 -37
- ksadk/toolsets/a2a.py +426 -0
- ksadk/toolsets/platform.py +21 -5
- ksadk/toolsets/sandbox.py +82 -16
- ksadk/toolsets/skills.py +200 -39
- ksadk/toolsets/web.py +123 -26
- ksadk/toolsets/workspace.py +212 -101
- ksadk/tracing/__init__.py +19 -21
- ksadk/tracing/exporters/inmemory_exporter.py +62 -51
- ksadk/tracing/setup.py +135 -506
- ksadk/tracing/span_utils.py +0 -41
- ksadk/tui/loop.py +78 -30
- ksadk/tui/stream_render.py +1 -0
- ksadk/ui_config.py +5 -3
- ksadk/version.py +1 -1
- ksadk_runtime_common/memory_backend/registry.py +56 -56
- ksadk_runtime_common/schemas/runtime_event_v1.json +95 -0
- ksadk_runtime_common/workspace_files/router.py +8 -2
- agentengine_sdk_python-0.7.0.dist-info/RECORD +0 -482
- ksadk/a2a/card_builder.py +0 -64
- ksadk/a2a/client.py +0 -309
- ksadk/runners/utils/langfuse.py +0 -230
- ksadk/server/static/assets/CodeBlock-P16VOLYi.js +0 -9
- ksadk/server/static/assets/MathMessageMarkdown-CdGiQWHR.js +0 -8
- ksadk/server/static/assets/MermaidBlock-IOcal8cm.js +0 -303
- ksadk/server/static/assets/NativeTerminalPanel-DGSDWsei.js +0 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-BvUlsA6l.js +0 -1
- ksadk/server/static/assets/channel-CTuydARX.js +0 -1
- ksadk/server/static/assets/chunk-QZHKN3VN-BnCydivS.js +0 -1
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-BNHg45Be.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-BNHg45Be.js +0 -1
- ksadk/server/static/assets/eventmodeling-FCH6USID-DsAgWnlf.js +0 -1
- ksadk/server/static/assets/gitGraph-WXDBUCRP-BIao9Yjg.js +0 -1
- ksadk/server/static/assets/index-C00Lwg3L.js +0 -165
- ksadk/server/static/assets/index-DAURbCsP.css +0 -1
- ksadk/server/static/assets/info-J43DQDTF-CyipqGxU.js +0 -1
- ksadk/server/static/assets/packet-YPE3B663-CGkyRxlg.js +0 -1
- ksadk/server/static/assets/pie-LRSECV5Y-M0uWAf4n.js +0 -1
- ksadk/server/static/assets/radar-GUYGQ44K-Bdbm24-x.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-8xBN_gLM.js +0 -1
- ksadk/server/static/assets/treeView-BLDUP644-npMo0ak1.js +0 -1
- ksadk/server/static/assets/treemap-LRROVOQU-CHdzrrdo.js +0 -1
- ksadk/server/static/assets/wardley-L42UT6IY-BEQz7wyy.js +0 -1
- ksadk/tracing/exporters/langfuse_exporter.py +0 -445
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
"""Session, UI bootstrap, checkpoint-list, and tool-receipt routes."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from fastapi import HTTPException
|
|
9
|
+
|
|
10
|
+
from ksadk.server.factory import get_runtime_execution, get_state
|
|
11
|
+
from ksadk.sessions import SessionEvent
|
|
12
|
+
from ksadk.tools.gateway import tool_approval_capability
|
|
13
|
+
from ksadk.toolsets import describe_agentengine_tools
|
|
14
|
+
from ksadk_runtime_common.workspace_files import (
|
|
15
|
+
build_workspace_files_bootstrap,
|
|
16
|
+
workspace_files_enabled,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from . import dependencies as deps
|
|
20
|
+
from .common import (
|
|
21
|
+
_action_response,
|
|
22
|
+
_build_bootstrap_model_payload,
|
|
23
|
+
_build_native_terminal_capability,
|
|
24
|
+
_ensure_session,
|
|
25
|
+
_hydrate_session,
|
|
26
|
+
_resolve_agent_ui_spec,
|
|
27
|
+
)
|
|
28
|
+
from .models import (
|
|
29
|
+
CreateSessionActionRequest,
|
|
30
|
+
ListSessionCheckpointsActionRequest,
|
|
31
|
+
ListSessionEventsActionRequest,
|
|
32
|
+
ListSessionMessagesActionRequest,
|
|
33
|
+
ListSessionsActionRequest,
|
|
34
|
+
ListToolReceiptsActionRequest,
|
|
35
|
+
SessionIdRequest,
|
|
36
|
+
UiBootstrapRequest,
|
|
37
|
+
_event_run_id,
|
|
38
|
+
_runtime_agent_id,
|
|
39
|
+
)
|
|
40
|
+
from .projection import (
|
|
41
|
+
_apply_checkpoint_resume_audit,
|
|
42
|
+
_apply_latest_checkpoint_policy,
|
|
43
|
+
_checkpoint_event_to_action_payload,
|
|
44
|
+
_event_invocation_id,
|
|
45
|
+
_event_to_action_payload,
|
|
46
|
+
_extend_invocation_after_window,
|
|
47
|
+
_extend_invocation_before_window,
|
|
48
|
+
_iter_scoped_event_pages,
|
|
49
|
+
_iter_session_event_pages,
|
|
50
|
+
_record_resume_audit,
|
|
51
|
+
_require_action_session,
|
|
52
|
+
_session_to_action_payload,
|
|
53
|
+
_tool_receipt_event_to_action_payload,
|
|
54
|
+
)
|
|
55
|
+
from .routers import sessions_router, tools_router, ui_bootstrap_router
|
|
56
|
+
from .streaming import _cancel_detached_streams_for_session
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@ui_bootstrap_router.post("/agentengine/api/v1/GetAgentUiBootstrap")
|
|
60
|
+
async def get_agent_ui_bootstrap(request: UiBootstrapRequest):
|
|
61
|
+
state = get_state()
|
|
62
|
+
executor, launch_context = get_runtime_execution()
|
|
63
|
+
detection = launch_context.detection
|
|
64
|
+
agent_id = request.AgentId or _runtime_agent_id(launch_context)
|
|
65
|
+
description = str(getattr(detection, "description", "") or "")
|
|
66
|
+
framework = launch_context.runtime_type.strip().lower()
|
|
67
|
+
workspace_enabled = workspace_files_enabled(default=True)
|
|
68
|
+
ui_spec = _resolve_agent_ui_spec()
|
|
69
|
+
runtime_capabilities = executor.native_capabilities(launch_context)
|
|
70
|
+
resume_capability = (
|
|
71
|
+
runtime_capabilities.get("ResumeRun")
|
|
72
|
+
if isinstance(runtime_capabilities, Mapping)
|
|
73
|
+
else None
|
|
74
|
+
)
|
|
75
|
+
resume_capability = resume_capability if isinstance(resume_capability, Mapping) else {}
|
|
76
|
+
checkpoint_capability = (
|
|
77
|
+
runtime_capabilities.get("Checkpoint")
|
|
78
|
+
if isinstance(runtime_capabilities, Mapping)
|
|
79
|
+
else None
|
|
80
|
+
)
|
|
81
|
+
checkpoint_capability = (
|
|
82
|
+
checkpoint_capability if isinstance(checkpoint_capability, Mapping) else {}
|
|
83
|
+
)
|
|
84
|
+
cancel_capability = (
|
|
85
|
+
runtime_capabilities.get("CancelRun")
|
|
86
|
+
if isinstance(runtime_capabilities, Mapping)
|
|
87
|
+
else None
|
|
88
|
+
)
|
|
89
|
+
cancel_capability = cancel_capability if isinstance(cancel_capability, Mapping) else {}
|
|
90
|
+
checkpoint_resume_capability = {
|
|
91
|
+
"Supported": bool(resume_capability.get("Supported")),
|
|
92
|
+
"Checkpoint": checkpoint_capability,
|
|
93
|
+
"ResumeRun": resume_capability,
|
|
94
|
+
}
|
|
95
|
+
checkpoint_resume_supported = bool(checkpoint_resume_capability["Supported"])
|
|
96
|
+
cancel_run_supported = bool(cancel_capability.get("Supported"))
|
|
97
|
+
responses_transport = {
|
|
98
|
+
"Protocol": "responses",
|
|
99
|
+
"Runtime": "ksadk",
|
|
100
|
+
"Endpoint": "/v1/responses",
|
|
101
|
+
"Version": "v1",
|
|
102
|
+
"Capabilities": {
|
|
103
|
+
"A2UI": False,
|
|
104
|
+
"Interrupt": checkpoint_resume_supported,
|
|
105
|
+
"Cancel": cancel_run_supported,
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
hosted_chat_transports = []
|
|
109
|
+
if state.agui_agent is not None and state.agui_config is not None:
|
|
110
|
+
from ksadk.agui.config import AGUI_PROTOCOL_VERSION
|
|
111
|
+
|
|
112
|
+
hosted_chat_transports.append(
|
|
113
|
+
{
|
|
114
|
+
"Protocol": "ag-ui",
|
|
115
|
+
"Runtime": "copilotkit",
|
|
116
|
+
"Endpoint": state.agui_config.path,
|
|
117
|
+
"Version": AGUI_PROTOCOL_VERSION,
|
|
118
|
+
"Capabilities": {
|
|
119
|
+
"A2UI": True,
|
|
120
|
+
"Interrupt": checkpoint_resume_supported,
|
|
121
|
+
"Cancel": True,
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
hosted_chat_transports.append(responses_transport)
|
|
126
|
+
preferred_transport = (
|
|
127
|
+
"ag-ui"
|
|
128
|
+
if hosted_chat_transports[0]["Protocol"] == "ag-ui"
|
|
129
|
+
and bool(getattr(state.agui_config, "preferred", False))
|
|
130
|
+
else "responses"
|
|
131
|
+
)
|
|
132
|
+
return _action_response(
|
|
133
|
+
"GetAgentUiBootstrap",
|
|
134
|
+
{
|
|
135
|
+
"Agent": {
|
|
136
|
+
"AgentId": agent_id,
|
|
137
|
+
"Name": str(getattr(detection, "name", "") or agent_id),
|
|
138
|
+
"Description": description or "",
|
|
139
|
+
"Framework": framework,
|
|
140
|
+
},
|
|
141
|
+
"Modules": ["Chat", "Build", "Deploy"],
|
|
142
|
+
"Capabilities": {
|
|
143
|
+
"Attachments": True,
|
|
144
|
+
"WorkspaceFiles": workspace_enabled,
|
|
145
|
+
"Approval": True,
|
|
146
|
+
"ApprovalPolicy": tool_approval_capability(),
|
|
147
|
+
"Thinking": True,
|
|
148
|
+
"StopRun": cancel_run_supported,
|
|
149
|
+
"ResumeRun": checkpoint_resume_supported,
|
|
150
|
+
"RuntimeCapabilities": runtime_capabilities,
|
|
151
|
+
"CheckpointResumeCapability": checkpoint_resume_capability,
|
|
152
|
+
"RunLifecycle": {
|
|
153
|
+
"Enabled": True,
|
|
154
|
+
"Resume": True,
|
|
155
|
+
"Abort": True,
|
|
156
|
+
"Checkpoints": checkpoint_resume_supported,
|
|
157
|
+
"CheckpointResume": checkpoint_resume_supported,
|
|
158
|
+
"CheckpointResumePreview": checkpoint_resume_supported,
|
|
159
|
+
},
|
|
160
|
+
"MCP": False,
|
|
161
|
+
"HostedRuntime": False,
|
|
162
|
+
"NativeTerminal": _build_native_terminal_capability(framework),
|
|
163
|
+
"BuiltinTools": describe_agentengine_tools(),
|
|
164
|
+
},
|
|
165
|
+
"WorkspaceFiles": build_workspace_files_bootstrap(enabled=workspace_enabled),
|
|
166
|
+
"AccessMode": "Owner",
|
|
167
|
+
"SharePermissions": {
|
|
168
|
+
"Interactive": True,
|
|
169
|
+
"DefaultPath": ui_spec.get("ui_path") or ui_spec.get("path") or "/chat",
|
|
170
|
+
"SharePath": ui_spec.get("ui_path") or ui_spec.get("path") or "/chat",
|
|
171
|
+
},
|
|
172
|
+
"CustomUI": {
|
|
173
|
+
"Enabled": bool(ui_spec.get("enabled")),
|
|
174
|
+
"Profile": ui_spec.get("ui_profile") or ui_spec.get("profile"),
|
|
175
|
+
"Path": ui_spec.get("ui_path") or ui_spec.get("path"),
|
|
176
|
+
"Url": ui_spec.get("ui_url") or ui_spec.get("url"),
|
|
177
|
+
"BundlePath": ui_spec.get("ui_bundle_path") or ui_spec.get("bundle_path"),
|
|
178
|
+
},
|
|
179
|
+
"ApiFormats": ["responses", "chat_completions"],
|
|
180
|
+
"HostedChat": {
|
|
181
|
+
"PreferredTransport": preferred_transport,
|
|
182
|
+
"Transports": hosted_chat_transports,
|
|
183
|
+
},
|
|
184
|
+
"Stream": True,
|
|
185
|
+
"SessionId": request.SessionId,
|
|
186
|
+
"SessionBackend": deps.describe_session_backend(),
|
|
187
|
+
"HostedRuntime": None,
|
|
188
|
+
"Model": _build_bootstrap_model_payload(),
|
|
189
|
+
},
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@sessions_router.post("/agentengine/api/v1/CreateSession")
|
|
194
|
+
async def create_session_action(request: CreateSessionActionRequest):
|
|
195
|
+
session = await _ensure_session(request.AgentId, request.UserId or "user", request.SessionId)
|
|
196
|
+
return _action_response("CreateSession", {"Session": await _session_to_action_payload(session)})
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
@sessions_router.post("/agentengine/api/v1/ListSessions")
|
|
200
|
+
async def list_sessions_action(request: ListSessionsActionRequest):
|
|
201
|
+
service = deps.resolve_session_service()
|
|
202
|
+
offset = (request.Page - 1) * request.PageSize
|
|
203
|
+
sessions = await service.list_sessions(
|
|
204
|
+
request.AgentId,
|
|
205
|
+
request.UserId,
|
|
206
|
+
offset=offset,
|
|
207
|
+
limit=request.PageSize,
|
|
208
|
+
)
|
|
209
|
+
total = await service.count_sessions(request.AgentId, request.UserId)
|
|
210
|
+
session_payloads = [await _session_to_action_payload(session) for session in sessions]
|
|
211
|
+
return _action_response(
|
|
212
|
+
"ListSessions",
|
|
213
|
+
{
|
|
214
|
+
"Sessions": session_payloads,
|
|
215
|
+
"Total": total,
|
|
216
|
+
"Page": request.Page,
|
|
217
|
+
"PageSize": request.PageSize,
|
|
218
|
+
"DataSource": "runtime",
|
|
219
|
+
"Degraded": False,
|
|
220
|
+
"SessionContractVersion": 2,
|
|
221
|
+
},
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@sessions_router.post("/agentengine/api/v1/GetSession")
|
|
226
|
+
async def get_session_action(request: SessionIdRequest):
|
|
227
|
+
service = deps.resolve_session_service()
|
|
228
|
+
session = await _require_action_session(
|
|
229
|
+
service,
|
|
230
|
+
session_id=request.SessionId,
|
|
231
|
+
agent_id=request.AgentId,
|
|
232
|
+
user_id=request.UserId,
|
|
233
|
+
)
|
|
234
|
+
hydrated = await _hydrate_session(session)
|
|
235
|
+
if hydrated is None:
|
|
236
|
+
raise HTTPException(status_code=404, detail="Session not found")
|
|
237
|
+
return _action_response("GetSession", {"Session": await _session_to_action_payload(hydrated)})
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
@sessions_router.post("/agentengine/api/v1/DeleteSession")
|
|
241
|
+
async def delete_session_action(request: SessionIdRequest):
|
|
242
|
+
service = deps.resolve_session_service()
|
|
243
|
+
await _require_action_session(
|
|
244
|
+
service,
|
|
245
|
+
session_id=request.SessionId,
|
|
246
|
+
agent_id=request.AgentId,
|
|
247
|
+
user_id=request.UserId,
|
|
248
|
+
)
|
|
249
|
+
await _cancel_detached_streams_for_session(request.SessionId)
|
|
250
|
+
deleted = await service.delete_session(request.SessionId)
|
|
251
|
+
if not deleted:
|
|
252
|
+
raise HTTPException(status_code=404, detail="Session not found")
|
|
253
|
+
return _action_response("DeleteSession", {"Deleted": True})
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
@sessions_router.post("/agentengine/api/v1/ListSessionEvents")
|
|
257
|
+
async def list_session_events_action(request: ListSessionEventsActionRequest):
|
|
258
|
+
_executor, launch_context = get_runtime_execution()
|
|
259
|
+
service = deps.resolve_session_service()
|
|
260
|
+
session_id = str(request.SessionId or "").strip()
|
|
261
|
+
if not session_id:
|
|
262
|
+
# 未传 SessionId:返回该 agent 全部会话的事件(存储层跨会话查询,真分页无截断;
|
|
263
|
+
# seq 游标是会话内序号,跨会话模式下不适用,直接忽略)
|
|
264
|
+
agent_id = str(request.AgentId or "").strip() or _runtime_agent_id(launch_context)
|
|
265
|
+
events = await service.get_events_for_agent(
|
|
266
|
+
agent_id,
|
|
267
|
+
user_id=request.UserId,
|
|
268
|
+
offset=request.Offset,
|
|
269
|
+
limit=request.Limit,
|
|
270
|
+
)
|
|
271
|
+
total = await service.count_events_for_agent(agent_id, user_id=request.UserId)
|
|
272
|
+
return _action_response(
|
|
273
|
+
"ListSessionEvents",
|
|
274
|
+
{
|
|
275
|
+
"Events": [_event_to_action_payload(event) for event in events],
|
|
276
|
+
"Total": total,
|
|
277
|
+
"Offset": request.Offset or 0,
|
|
278
|
+
"Limit": request.Limit if request.Limit is not None else len(events),
|
|
279
|
+
"AfterSeqId": request.AfterSeqId,
|
|
280
|
+
"BeforeSeqId": request.BeforeSeqId,
|
|
281
|
+
"ScopedAllSessions": True,
|
|
282
|
+
},
|
|
283
|
+
)
|
|
284
|
+
await _require_action_session(
|
|
285
|
+
service,
|
|
286
|
+
session_id=session_id,
|
|
287
|
+
agent_id=request.AgentId,
|
|
288
|
+
user_id=request.UserId,
|
|
289
|
+
)
|
|
290
|
+
events = await service.get_events(
|
|
291
|
+
session_id,
|
|
292
|
+
offset=request.Offset,
|
|
293
|
+
limit=request.Limit,
|
|
294
|
+
after_seq_id=request.AfterSeqId,
|
|
295
|
+
before_seq_id=request.BeforeSeqId,
|
|
296
|
+
)
|
|
297
|
+
total = await service.count_events(
|
|
298
|
+
session_id,
|
|
299
|
+
after_seq_id=request.AfterSeqId,
|
|
300
|
+
before_seq_id=request.BeforeSeqId,
|
|
301
|
+
)
|
|
302
|
+
return _action_response(
|
|
303
|
+
"ListSessionEvents",
|
|
304
|
+
{
|
|
305
|
+
"Events": [_event_to_action_payload(event) for event in events],
|
|
306
|
+
"Total": total,
|
|
307
|
+
"Offset": request.Offset or 0,
|
|
308
|
+
"Limit": request.Limit if request.Limit is not None else len(events),
|
|
309
|
+
"AfterSeqId": request.AfterSeqId,
|
|
310
|
+
"BeforeSeqId": request.BeforeSeqId,
|
|
311
|
+
},
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
@sessions_router.post("/agentengine/api/v1/ListSessionMessages")
|
|
316
|
+
async def list_session_messages_action(request: ListSessionMessagesActionRequest):
|
|
317
|
+
from ksadk.conversations.message_projection import project_session_messages
|
|
318
|
+
|
|
319
|
+
service = deps.resolve_session_service()
|
|
320
|
+
await _require_action_session(
|
|
321
|
+
service,
|
|
322
|
+
session_id=request.SessionId,
|
|
323
|
+
agent_id=request.AgentId,
|
|
324
|
+
user_id=request.UserId,
|
|
325
|
+
)
|
|
326
|
+
total_events = await service.count_events(
|
|
327
|
+
request.SessionId,
|
|
328
|
+
after_seq_id=request.AfterSeqId,
|
|
329
|
+
before_seq_id=request.BeforeSeqId,
|
|
330
|
+
)
|
|
331
|
+
event_offset = 0
|
|
332
|
+
if request.AfterSeqId is not None and total_events > 2000:
|
|
333
|
+
# Storage pagination is tail-based. Offset past the newest surplus so
|
|
334
|
+
# reconnect starts with the oldest unseen window and cannot skip gaps.
|
|
335
|
+
event_offset = total_events - 2000
|
|
336
|
+
events = await service.get_events(
|
|
337
|
+
request.SessionId,
|
|
338
|
+
offset=event_offset,
|
|
339
|
+
limit=2000,
|
|
340
|
+
after_seq_id=request.AfterSeqId,
|
|
341
|
+
before_seq_id=request.BeforeSeqId,
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
def project(
|
|
345
|
+
events_to_project: list[SessionEvent],
|
|
346
|
+
) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
|
347
|
+
serialized = [_event_to_action_payload(event) for event in events_to_project]
|
|
348
|
+
return serialized, project_session_messages(
|
|
349
|
+
serialized,
|
|
350
|
+
include_reasoning=request.IncludeReasoning,
|
|
351
|
+
include_tool_events=request.IncludeToolEvents,
|
|
352
|
+
include_attachments=request.IncludeAttachments,
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
serialized_events, messages = project(events)
|
|
356
|
+
if request.AfterSeqId is not None:
|
|
357
|
+
if total_events > len(events):
|
|
358
|
+
events = await _extend_invocation_after_window(
|
|
359
|
+
service,
|
|
360
|
+
request.SessionId,
|
|
361
|
+
events,
|
|
362
|
+
before_seq_id=request.BeforeSeqId,
|
|
363
|
+
)
|
|
364
|
+
serialized_events, messages = project(events)
|
|
365
|
+
page = messages
|
|
366
|
+
has_more = total_events > len(serialized_events)
|
|
367
|
+
next_cursor = None
|
|
368
|
+
else:
|
|
369
|
+
page_start = len(messages)
|
|
370
|
+
while page_start > 0:
|
|
371
|
+
group_start_seq_id = int(messages[page_start - 1].get("StartSeqId") or 0)
|
|
372
|
+
group_start_index = next(
|
|
373
|
+
(
|
|
374
|
+
index
|
|
375
|
+
for index, message in enumerate(messages[:page_start])
|
|
376
|
+
if int(message.get("StartSeqId") or 0) == group_start_seq_id
|
|
377
|
+
),
|
|
378
|
+
page_start - 1,
|
|
379
|
+
)
|
|
380
|
+
current_size = len(messages) - page_start
|
|
381
|
+
group_size = page_start - group_start_index
|
|
382
|
+
if current_size and current_size + group_size > request.Limit:
|
|
383
|
+
break
|
|
384
|
+
page_start = group_start_index
|
|
385
|
+
if len(messages) - page_start >= request.Limit:
|
|
386
|
+
break
|
|
387
|
+
page = messages[page_start:]
|
|
388
|
+
if (
|
|
389
|
+
page
|
|
390
|
+
and events
|
|
391
|
+
and total_events > len(events)
|
|
392
|
+
and _event_invocation_id(events[0])
|
|
393
|
+
and any(
|
|
394
|
+
str(message.get("InvocationId") or "") == _event_invocation_id(events[0])
|
|
395
|
+
for message in page
|
|
396
|
+
)
|
|
397
|
+
):
|
|
398
|
+
events = await _extend_invocation_before_window(
|
|
399
|
+
service,
|
|
400
|
+
request.SessionId,
|
|
401
|
+
events,
|
|
402
|
+
after_seq_id=request.AfterSeqId,
|
|
403
|
+
)
|
|
404
|
+
serialized_events, messages = project(events)
|
|
405
|
+
page_start = len(messages)
|
|
406
|
+
while page_start > 0:
|
|
407
|
+
group_start_seq_id = int(messages[page_start - 1].get("StartSeqId") or 0)
|
|
408
|
+
group_start_index = next(
|
|
409
|
+
(
|
|
410
|
+
index
|
|
411
|
+
for index, message in enumerate(messages[:page_start])
|
|
412
|
+
if int(message.get("StartSeqId") or 0) == group_start_seq_id
|
|
413
|
+
),
|
|
414
|
+
page_start - 1,
|
|
415
|
+
)
|
|
416
|
+
current_size = len(messages) - page_start
|
|
417
|
+
group_size = page_start - group_start_index
|
|
418
|
+
if current_size and current_size + group_size > request.Limit:
|
|
419
|
+
break
|
|
420
|
+
page_start = group_start_index
|
|
421
|
+
if len(messages) - page_start >= request.Limit:
|
|
422
|
+
break
|
|
423
|
+
page = messages[page_start:]
|
|
424
|
+
minimum_start_seq_id = int(page[0].get("StartSeqId") or 0) if page else 0
|
|
425
|
+
has_more = page_start > 0 or total_events > len(serialized_events)
|
|
426
|
+
# BeforeSeqId is exclusive. Use the invocation group boundary so the
|
|
427
|
+
# next page cannot duplicate reasoning/tools or skip its user message.
|
|
428
|
+
next_cursor = minimum_start_seq_id if has_more else None
|
|
429
|
+
latest_seq_id = (
|
|
430
|
+
int(page[-1].get("SeqId") or 0)
|
|
431
|
+
if page
|
|
432
|
+
else max(
|
|
433
|
+
(int(event.get("SeqId") or 0) for event in serialized_events),
|
|
434
|
+
default=int(request.AfterSeqId or 0),
|
|
435
|
+
)
|
|
436
|
+
)
|
|
437
|
+
return _action_response(
|
|
438
|
+
"ListSessionMessages",
|
|
439
|
+
{
|
|
440
|
+
"SessionId": request.SessionId,
|
|
441
|
+
"Messages": page,
|
|
442
|
+
"LatestSeqId": latest_seq_id,
|
|
443
|
+
"HasMore": has_more,
|
|
444
|
+
"NextCursor": next_cursor,
|
|
445
|
+
},
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def _count_resumable_checkpoints(checkpoints: list[dict[str, Any]]) -> int:
|
|
450
|
+
"""统计可恢复 checkpoint 数量。
|
|
451
|
+
|
|
452
|
+
规则:IsResumable=True AND ReplayAllowed!=False AND IsTerminal!=True
|
|
453
|
+
AND CheckpointStatus not in {expired, disabled}。
|
|
454
|
+
不排除 resumed(已恢复过的仍计入,符合存档点可反复读的回档语义)。
|
|
455
|
+
"""
|
|
456
|
+
resumable = 0
|
|
457
|
+
for cp in checkpoints:
|
|
458
|
+
if cp.get("IsResumable") is not True:
|
|
459
|
+
continue
|
|
460
|
+
if cp.get("ReplayAllowed") is False:
|
|
461
|
+
continue
|
|
462
|
+
if cp.get("IsTerminal") is True:
|
|
463
|
+
continue
|
|
464
|
+
status = str(cp.get("CheckpointStatus") or "").strip().lower()
|
|
465
|
+
if status in {"expired", "disabled"}:
|
|
466
|
+
continue
|
|
467
|
+
resumable += 1
|
|
468
|
+
return resumable
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
async def _list_checkpoints_payload(request: ListSessionCheckpointsActionRequest) -> dict[str, Any]:
|
|
472
|
+
service = deps.resolve_session_service()
|
|
473
|
+
run_id_filter = str(request.RunId or "").strip()
|
|
474
|
+
framework_filter = str(request.Framework or "").strip().lower()
|
|
475
|
+
|
|
476
|
+
session_id = str(request.SessionId or "").strip()
|
|
477
|
+
if session_id:
|
|
478
|
+
await _require_action_session(
|
|
479
|
+
service,
|
|
480
|
+
session_id=session_id,
|
|
481
|
+
agent_id=request.AgentId,
|
|
482
|
+
user_id=request.UserId,
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
audit_by_session: dict[str, dict[tuple[str, str], dict[str, Any]]] = {}
|
|
486
|
+
latest_by_session_run: dict[tuple[str, str], int] = {}
|
|
487
|
+
run_seen = not run_id_filter
|
|
488
|
+
async for page in _iter_scoped_event_pages(
|
|
489
|
+
service,
|
|
490
|
+
session_id=session_id or None,
|
|
491
|
+
agent_id=request.AgentId,
|
|
492
|
+
user_id=request.UserId,
|
|
493
|
+
):
|
|
494
|
+
for event in page:
|
|
495
|
+
if run_id_filter and _event_run_id(event) == run_id_filter:
|
|
496
|
+
run_seen = True
|
|
497
|
+
_record_resume_audit(audit_by_session, event)
|
|
498
|
+
checkpoint = _checkpoint_event_to_action_payload(event)
|
|
499
|
+
if checkpoint is None or not (checkpoint.get("Metadata") or {}).get(
|
|
500
|
+
"only_latest_resumable"
|
|
501
|
+
):
|
|
502
|
+
continue
|
|
503
|
+
key = (event.session_id, str(checkpoint.get("RunId") or ""))
|
|
504
|
+
latest_by_session_run[key] = max(
|
|
505
|
+
latest_by_session_run.get(key, 0),
|
|
506
|
+
int(checkpoint.get("SeqId") or 0),
|
|
507
|
+
)
|
|
508
|
+
if session_id and not run_seen:
|
|
509
|
+
raise HTTPException(status_code=409, detail="RunId does not belong to SessionId")
|
|
510
|
+
|
|
511
|
+
def project_checkpoint(event: SessionEvent) -> dict[str, Any] | None:
|
|
512
|
+
checkpoint = _checkpoint_event_to_action_payload(event)
|
|
513
|
+
if checkpoint is None:
|
|
514
|
+
return None
|
|
515
|
+
checkpoint = _apply_checkpoint_resume_audit(
|
|
516
|
+
checkpoint,
|
|
517
|
+
audit_by_session.get(event.session_id, {}),
|
|
518
|
+
)
|
|
519
|
+
checkpoint = _apply_latest_checkpoint_policy(
|
|
520
|
+
checkpoint,
|
|
521
|
+
latest_by_session_run,
|
|
522
|
+
session_id=event.session_id,
|
|
523
|
+
)
|
|
524
|
+
if run_id_filter and checkpoint["RunId"] != run_id_filter:
|
|
525
|
+
return None
|
|
526
|
+
if framework_filter and str(checkpoint["Framework"]).lower() != framework_filter:
|
|
527
|
+
return None
|
|
528
|
+
return checkpoint
|
|
529
|
+
|
|
530
|
+
total = 0
|
|
531
|
+
resumable_total = 0
|
|
532
|
+
async for page in _iter_scoped_event_pages(
|
|
533
|
+
service,
|
|
534
|
+
session_id=session_id or None,
|
|
535
|
+
agent_id=request.AgentId,
|
|
536
|
+
user_id=request.UserId,
|
|
537
|
+
):
|
|
538
|
+
for event in page:
|
|
539
|
+
checkpoint = project_checkpoint(event)
|
|
540
|
+
if checkpoint is None:
|
|
541
|
+
continue
|
|
542
|
+
if checkpoint.get("IsResumable") is True:
|
|
543
|
+
resumable_total += 1
|
|
544
|
+
if request.OnlyResumable and checkpoint.get("IsResumable") is not True:
|
|
545
|
+
continue
|
|
546
|
+
total += 1
|
|
547
|
+
|
|
548
|
+
offset = int(request.Offset or 0)
|
|
549
|
+
limit = int(request.Limit)
|
|
550
|
+
window_end = max(total - offset, 0)
|
|
551
|
+
window_start = max(window_end - limit, 0)
|
|
552
|
+
checkpoints: list[dict[str, Any]] = []
|
|
553
|
+
filtered_index = 0
|
|
554
|
+
async for page in _iter_scoped_event_pages(
|
|
555
|
+
service,
|
|
556
|
+
session_id=session_id or None,
|
|
557
|
+
agent_id=request.AgentId,
|
|
558
|
+
user_id=request.UserId,
|
|
559
|
+
):
|
|
560
|
+
for event in page:
|
|
561
|
+
checkpoint = project_checkpoint(event)
|
|
562
|
+
if checkpoint is None:
|
|
563
|
+
continue
|
|
564
|
+
if request.OnlyResumable and checkpoint.get("IsResumable") is not True:
|
|
565
|
+
continue
|
|
566
|
+
if window_start <= filtered_index < window_end:
|
|
567
|
+
checkpoints.append(checkpoint)
|
|
568
|
+
filtered_index += 1
|
|
569
|
+
if filtered_index >= window_end:
|
|
570
|
+
break
|
|
571
|
+
if filtered_index >= window_end:
|
|
572
|
+
break
|
|
573
|
+
|
|
574
|
+
return {
|
|
575
|
+
"Checkpoints": checkpoints,
|
|
576
|
+
"Total": total,
|
|
577
|
+
"ResumableTotal": resumable_total,
|
|
578
|
+
"HasResumableCheckpoint": resumable_total > 0,
|
|
579
|
+
"Offset": offset,
|
|
580
|
+
"Limit": limit,
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
@sessions_router.post("/agentengine/api/v1/ListSessionCheckpoints")
|
|
585
|
+
async def list_session_checkpoints_action(request: ListSessionCheckpointsActionRequest):
|
|
586
|
+
return _action_response("ListSessionCheckpoints", await _list_checkpoints_payload(request))
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
@tools_router.post("/agentengine/api/v1/ListToolReceipts")
|
|
590
|
+
async def list_tool_receipts_action(request: ListToolReceiptsActionRequest):
|
|
591
|
+
service = deps.resolve_session_service()
|
|
592
|
+
await _require_action_session(
|
|
593
|
+
service,
|
|
594
|
+
session_id=request.SessionId,
|
|
595
|
+
agent_id=request.AgentId,
|
|
596
|
+
user_id=request.UserId,
|
|
597
|
+
)
|
|
598
|
+
|
|
599
|
+
run_id_filter = str(request.RunId or "").strip()
|
|
600
|
+
checkpoint_id_filter = str(request.CheckpointId or "").strip()
|
|
601
|
+
total = 0
|
|
602
|
+
async for page in _iter_session_event_pages(service, request.SessionId):
|
|
603
|
+
for event in page:
|
|
604
|
+
receipt = _tool_receipt_event_to_action_payload(event)
|
|
605
|
+
if receipt is None:
|
|
606
|
+
continue
|
|
607
|
+
if run_id_filter and receipt["RunId"] != run_id_filter:
|
|
608
|
+
continue
|
|
609
|
+
if checkpoint_id_filter and receipt["CheckpointId"] != checkpoint_id_filter:
|
|
610
|
+
continue
|
|
611
|
+
total += 1
|
|
612
|
+
|
|
613
|
+
offset = int(request.Offset)
|
|
614
|
+
limit = int(request.Limit)
|
|
615
|
+
window_end = max(total - offset, 0)
|
|
616
|
+
window_start = max(window_end - limit, 0)
|
|
617
|
+
receipts: list[dict[str, Any]] = []
|
|
618
|
+
filtered_index = 0
|
|
619
|
+
async for page in _iter_session_event_pages(service, request.SessionId):
|
|
620
|
+
for event in page:
|
|
621
|
+
receipt = _tool_receipt_event_to_action_payload(event)
|
|
622
|
+
if receipt is None:
|
|
623
|
+
continue
|
|
624
|
+
if run_id_filter and receipt["RunId"] != run_id_filter:
|
|
625
|
+
continue
|
|
626
|
+
if checkpoint_id_filter and receipt["CheckpointId"] != checkpoint_id_filter:
|
|
627
|
+
continue
|
|
628
|
+
if window_start <= filtered_index < window_end:
|
|
629
|
+
receipts.append(receipt)
|
|
630
|
+
filtered_index += 1
|
|
631
|
+
if filtered_index >= window_end:
|
|
632
|
+
break
|
|
633
|
+
if filtered_index >= window_end:
|
|
634
|
+
break
|
|
635
|
+
|
|
636
|
+
return _action_response(
|
|
637
|
+
"ListToolReceipts",
|
|
638
|
+
{
|
|
639
|
+
"ToolReceipts": receipts,
|
|
640
|
+
"Total": total,
|
|
641
|
+
"Offset": offset,
|
|
642
|
+
"Limit": limit,
|
|
643
|
+
},
|
|
644
|
+
)
|