agentengine-sdk-python 0.8.7__py3-none-any.whl → 0.8.9__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.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/METADATA +22 -20
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/RECORD +259 -221
- ksadk/__init__.py +2 -1
- ksadk/_build_provenance.json +1 -1
- ksadk/_mcp_compat.py +305 -0
- ksadk/agent.py +29 -0
- ksadk/agui/_agent_kernel.py +176 -142
- ksadk/agui/agent.py +75 -6
- ksadk/agui/hosted.py +343 -0
- ksadk/agui/request_identity.py +11 -0
- ksadk/agui/routes.py +77 -2
- ksadk/builders/code_builder.py +30 -23
- ksadk/builders/container_builder.py +5 -5
- ksadk/builders/framework_requirements.py +1 -1
- ksadk/builders/mcp_builder.py +142 -0
- ksadk/builders/project_imports.py +66 -0
- ksadk/cli/cmd_mcp.py +1 -1
- ksadk/cli/cmd_run.py +6 -4
- ksadk/cli/cmd_web.py +12 -0
- ksadk/cli/runtime_bootstrap.py +4 -1
- ksadk/cli/runtime_logging.py +30 -0
- ksadk/common/cloud_headers.py +33 -6
- ksadk/compat/adk_compat.py +2 -0
- ksadk/compat/adk_stream.py +35 -0
- ksadk/configs/env_registry.py +31 -0
- ksadk/context_engine/capabilities.py +13 -9
- ksadk/conversations/context.py +5 -0
- ksadk/conversations/message_projection.py +28 -19
- ksadk/conversations/projector.py +6 -0
- ksadk/conversations/runtime_compaction.py +6 -2
- ksadk/conversations/runtime_input.py +4 -0
- ksadk/conversations/runtime_invocation.py +5 -1
- ksadk/conversations/runtime_metadata.py +6 -7
- ksadk/conversations/runtime_observability.py +1 -0
- ksadk/conversations/runtime_payloads.py +5 -1
- ksadk/conversations/runtime_persistence.py +23 -0
- ksadk/conversations/runtime_preparation.py +128 -5
- ksadk/detection/mcp_detector.py +80 -22
- ksadk/events/adapters/langgraph.py +53 -1
- ksadk/harness/__init__.py +3 -0
- ksadk/harness/service_presentation.py +44 -0
- ksadk/harness/service_runtime.py +1038 -0
- ksadk/interaction/providers/harness.py +9 -4
- ksadk/kernel/control.py +16 -22
- ksadk/kernel/history_projection.py +191 -58
- ksadk/kernel/ingress.py +50 -26
- ksadk/kernel/postgres_event_log.py +10 -2
- ksadk/kernel/postgres_store.py +81 -2
- ksadk/kernel/run_references.py +38 -0
- ksadk/kernel/worker.py +2 -2
- ksadk/kernel/worker_controls.py +11 -1
- ksadk/kernel/worker_identity.py +15 -8
- ksadk/knowledge_base/client.py +10 -3
- ksadk/mcp_runtime/oauth/_agent.py +77 -9
- ksadk/mcp_runtime/oauth/kernel.py +5 -0
- ksadk/mcp_runtime/oauth/langgraph.py +47 -15
- ksadk/mcp_runtime/oauth/local/broker.py +41 -9
- ksadk/mcp_runtime/oauth/local/protocol.py +3 -11
- ksadk/mcp_runtime/oauth/local/transport.py +9 -2
- ksadk/mcp_runtime/oauth/tools.py +46 -8
- ksadk/mcp_runtime/oauth/transport.py +19 -2
- ksadk/memory/adk/backends/sdk_ltm_backend.py +21 -12
- ksadk/memory/scope_ids.py +49 -0
- ksadk/plugins/providers/harness.py +65 -28
- ksadk/plugins/providers/harness_service.py +198 -0
- ksadk/plugins/providers/harness_service_context.py +175 -0
- ksadk/plugins/providers/harness_service_hooks.py +168 -0
- ksadk/plugins/providers/harness_service_memory.py +479 -0
- ksadk/plugins/providers/platform_resources.py +2 -2
- ksadk/resource_runtime/contracts.py +39 -1
- ksadk/resource_runtime/langgraph.py +7 -3
- ksadk/resource_runtime/managed_projection.py +8 -6
- ksadk/resource_runtime/mcp_server.py +3 -3
- ksadk/resource_runtime/worker.py +27 -5
- ksadk/runners/_adk_canonical_stream.py +53 -24
- ksadk/runners/_adk_tunnel_history.py +96 -0
- ksadk/runners/_langgraph_answer_contract.py +1 -7
- ksadk/runners/_langgraph_canonical_stream.py +29 -6
- ksadk/runners/_langgraph_context.py +265 -0
- ksadk/runners/_langgraph_factory.py +79 -0
- ksadk/runners/_langgraph_model_budget.py +397 -0
- ksadk/runners/_langgraph_runner_streams.py +13 -6
- ksadk/runners/_session_identity.py +8 -3
- ksadk/runners/adk_runner.py +104 -36
- ksadk/runners/langgraph_runner.py +145 -29
- ksadk/runners/usage_accumulator.py +40 -0
- ksadk/runtime/conversation_execution.py +26 -4
- ksadk/runtime/factory.py +17 -5
- ksadk/runtime/framework_adapters.py +10 -0
- ksadk/runtime/langgraph_checkpoint_view.py +28 -7
- ksadk/runtime/launch.py +2 -0
- ksadk/server/factory.py +58 -1
- ksadk/server/routes/common.py +2 -0
- ksadk/server/routes/control.py +24 -8
- ksadk/server/routes/harness_service_view.py +38 -0
- ksadk/server/routes/history_items.py +157 -0
- ksadk/server/routes/kernel_ingress.py +51 -12
- ksadk/server/routes/local_kernel_control.py +16 -0
- ksadk/server/routes/models.py +26 -0
- ksadk/server/routes/openai_compat.py +10 -3
- ksadk/server/routes/projection.py +4 -0
- ksadk/server/routes/run.py +4 -2
- ksadk/server/routes/sessions.py +20 -1
- ksadk/server/routes/ui_bootstrap.py +16 -2
- ksadk/server/static/assets/{ArtifactsPanel-Cdr5C_vM.js → ArtifactsPanel-iZ_6CAQ2.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-BWRafud9.js → CodeBlock-D6uglm5n.js} +1 -1
- ksadk/server/static/assets/{MathMessageMarkdown-CFKeJIvy.js → MathMessageMarkdown-D6ojdxCG.js} +1 -1
- ksadk/server/static/assets/{MermaidBlock-BneAGUOd.js → MermaidBlock-Csk2ivT7.js} +6 -6
- ksadk/server/static/assets/{NativeTerminalPanel-BHI85zDO.js → NativeTerminalPanel-CCJA1XSH.js} +1 -1
- ksadk/server/static/assets/{OfficialA2uiRenderer-BOmT36lJ.js → OfficialA2uiRenderer-C06jus9N.js} +1 -1
- ksadk/server/static/assets/{abnfDiagram-VCTEODGH-DQvlOsBI.js → abnfDiagram-VCTEODGH-BhrF5tmL.js} +1 -1
- ksadk/server/static/assets/{arc-CGx0e4pN.js → arc-Btsh3kfy.js} +1 -1
- ksadk/server/static/assets/architecture-7GRP2DOG-BSXho3cq.js +1 -0
- ksadk/server/static/assets/{architectureDiagram-5GKGNRK7-WyybcNKX.js → architectureDiagram-5GKGNRK7-Cl8MfAmp.js} +1 -1
- ksadk/server/static/assets/{blockDiagram-NRAW4CY4-C9Cx_GVs.js → blockDiagram-NRAW4CY4-CeHSr8E_.js} +1 -1
- ksadk/server/static/assets/{c4Diagram-UCG6FXSJ-Bh7X3bGr.js → c4Diagram-UCG6FXSJ-BSD7RUKo.js} +1 -1
- ksadk/server/static/assets/channel-BpyDVKis.js +1 -0
- ksadk/server/static/assets/chunk-2Q5K7J3B-HLcpmPI2.js +1 -0
- ksadk/server/static/assets/{chunk-5VM5RSS4-cP9XupZj.js → chunk-5VM5RSS4-wz0pkBjp.js} +1 -1
- ksadk/server/static/assets/{chunk-F27PBJKO-Bm77fvR9.js → chunk-F27PBJKO-shjQ7cPM.js} +1 -1
- ksadk/server/static/assets/{chunk-G27WJ6UU-DDKNPesQ.js → chunk-G27WJ6UU-DL_MfUsu.js} +1 -1
- ksadk/server/static/assets/{chunk-JWPE2WC7-BqiUDB7s.js → chunk-JWPE2WC7-moUdwYpb.js} +1 -1
- ksadk/server/static/assets/{chunk-LCL6LL3I-C528mMZy.js → chunk-LCL6LL3I-B3QcDsZM.js} +1 -1
- ksadk/server/static/assets/{chunk-POPQ4Y6H-CzZ9g_Uf.js → chunk-POPQ4Y6H-BLBKb48A.js} +1 -1
- ksadk/server/static/assets/{chunk-RHFEMEQ7-CXj4tUZ-.js → chunk-RHFEMEQ7-CXR6ZzOx.js} +1 -1
- ksadk/server/static/assets/{chunk-SVP7TREG-BHyd85pS.js → chunk-SVP7TREG-DoR8BxkO.js} +1 -1
- ksadk/server/static/assets/{chunk-XXDRQBXY-Qe29PHGe.js → chunk-XXDRQBXY-8HJaIq0q.js} +1 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DlNiRtSN.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DlNiRtSN.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-JH36ORCC-maRKgeec.js → cose-bilkent-JH36ORCC-DnSSHHqS.js} +1 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-DxNym3qg.js +1 -0
- ksadk/server/static/assets/{cynefinDiagram-5FMLGOSQ-CoD0bEvn.js → cynefinDiagram-5FMLGOSQ-4eCi_Rw5.js} +1 -1
- ksadk/server/static/assets/{dagre-3AP2YEHR-BkpgQqyW.js → dagre-3AP2YEHR-DpPk9jsh.js} +1 -1
- ksadk/server/static/assets/{dagre-BUaTFrYa.js → dagre-G789Mawt.js} +1 -1
- ksadk/server/static/assets/{diagram-S7CK7UJ4-25HdTbjE.js → diagram-S7CK7UJ4-7x2FScRJ.js} +1 -1
- ksadk/server/static/assets/{diagram-UQ7AKVKN-KO-WqOIg.js → diagram-UQ7AKVKN-DGvliWDD.js} +1 -1
- ksadk/server/static/assets/{diagram-VSXAHHWV-B360BkDQ.js → diagram-VSXAHHWV-C0i4uEyS.js} +1 -1
- ksadk/server/static/assets/{diagram-VX7I27RA-COr1Oqsg.js → diagram-VX7I27RA-C7SmgIl5.js} +1 -1
- ksadk/server/static/assets/{diagram-Z3DM3KII-CgaKrIwB.js → diagram-Z3DM3KII-Xca7TB4U.js} +1 -1
- ksadk/server/static/assets/{dist-By-MVndb.js → dist-B3rsrE8r.js} +1 -1
- ksadk/server/static/assets/{dist-Bsuusoi0.js → dist-BM6KIyhr.js} +1 -1
- ksadk/server/static/assets/{dist-DzdXSBJb.js → dist-BMZKBrmN.js} +1 -1
- ksadk/server/static/assets/{dist-DmWw0IXB.js → dist-BUGNcOx8.js} +1 -1
- ksadk/server/static/assets/{dist-DXOlCAay.js → dist-BbIN_x76.js} +1 -1
- ksadk/server/static/assets/{dist--HftQyp9.js → dist-CGB89Aru.js} +1 -1
- ksadk/server/static/assets/{dist-DKG0OYnk.js → dist-CGIWL8mC.js} +1 -1
- ksadk/server/static/assets/{dist-DgJ57sRe.js → dist-CHeuPGXZ.js} +1 -1
- ksadk/server/static/assets/{dist-_0Xgu_07.js → dist-CMJq3QL-.js} +1 -1
- ksadk/server/static/assets/{dist-CwnkOyDn.js → dist-CiUeIDKz.js} +1 -1
- ksadk/server/static/assets/{dist-BoRn8a_t.js → dist-CmaZEf5M.js} +1 -1
- ksadk/server/static/assets/{dist-BQ116UdZ.js → dist-Cq4qlsg3.js} +1 -1
- ksadk/server/static/assets/{dist-CBo9AHUv.js → dist-DDVDyH7h.js} +1 -1
- ksadk/server/static/assets/{dist-DSw5Ju6-.js → dist-DDi9q5bO.js} +1 -1
- ksadk/server/static/assets/{dist-CxIl4t92.js → dist-DJ8mj6p4.js} +1 -1
- ksadk/server/static/assets/{dist-Brbrdmff.js → dist-DRGym1nc.js} +1 -1
- ksadk/server/static/assets/{dist-BEbS8Bag.js → dist-DcrTYAeW.js} +1 -1
- ksadk/server/static/assets/{dist-C9BTMVwS.js → dist-DpuxDDLa.js} +1 -1
- ksadk/server/static/assets/{dist-B3Jp5r1e.js → dist-EFGQ7G_k.js} +1 -1
- ksadk/server/static/assets/{dist-HHvdjADB.js → dist-IyCF0NNA.js} +1 -1
- ksadk/server/static/assets/{dist-Bxcu8Ca0.js → dist-Ny95vkRV.js} +1 -1
- ksadk/server/static/assets/{dist-CR61WJFC.js → dist-s5cohO5C.js} +1 -1
- ksadk/server/static/assets/{ebnfDiagram-PWID7BFC-DogDP2db.js → ebnfDiagram-PWID7BFC-DNwVczAJ.js} +1 -1
- ksadk/server/static/assets/{erDiagram-SSCWMZ5O-CeBDnUjR.js → erDiagram-SSCWMZ5O-OxFlhx6v.js} +1 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-C-gXDupK.js +1 -0
- ksadk/server/static/assets/flowDiagram-A5DVABFB-CkpCYD4e.js +1 -0
- ksadk/server/static/assets/{ganttDiagram-EL5Y4UJY-oIQL3MCp.js → ganttDiagram-EL5Y4UJY-D4krNgUz.js} +1 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-0RSkEgC5.js +1 -0
- ksadk/server/static/assets/{gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js → gitGraphDiagram-WWUBYQGX-BUSVPN1s.js} +1 -1
- ksadk/server/static/assets/index-B9UP7He9.css +2 -0
- ksadk/server/static/assets/index-COn4kn-G.js +1135 -0
- ksadk/server/static/assets/info-A6RAGUB7-C6KX7WO4.js +1 -0
- ksadk/server/static/assets/{infoDiagram-RXCK75RN-yQRC41Ya.js → infoDiagram-RXCK75RN-b6w3u3-O.js} +1 -1
- ksadk/server/static/assets/{ishikawaDiagram-5VMMS53U-BCu4HiwL.js → ishikawaDiagram-5VMMS53U-CsC7gzRt.js} +1 -1
- ksadk/server/static/assets/{journeyDiagram-EYS64GPL-JaqmO73K.js → journeyDiagram-EYS64GPL-BATLNoy1.js} +1 -1
- ksadk/server/static/assets/{kanban-definition-3QL26DDD-DQo4X8NO.js → kanban-definition-3QL26DDD-C49zL_s0.js} +1 -1
- ksadk/server/static/assets/{katex-t_DWylQw.js → katex-CDVgGGy2.js} +1 -1
- ksadk/server/static/assets/{linear-DWdnI35B.js → linear-DkyDumSy.js} +1 -1
- ksadk/server/static/assets/{mermaid-parser.core-BHrT2Pfe.js → mermaid-parser.core-BDX-LqSy.js} +2 -2
- ksadk/server/static/assets/{mindmap-definition-FBJOCRG2-PBVAhZYV.js → mindmap-definition-FBJOCRG2-DRPnzL2n.js} +1 -1
- ksadk/server/static/assets/packet-AYTQ26CC-CMMupxPW.js +1 -0
- ksadk/server/static/assets/{pegDiagram-XKGWAZYB-CU_cLfow.js → pegDiagram-XKGWAZYB-Zm-xrNrr.js} +1 -1
- ksadk/server/static/assets/pie-WAS4IAKB-Bfo0pa9v.js +1 -0
- ksadk/server/static/assets/{pieDiagram-E7YTZNPT-B1h0-_pW.js → pieDiagram-E7YTZNPT-a8C1Jxo4.js} +1 -1
- ksadk/server/static/assets/{quadrantDiagram-AXDQQJYC-DEMoGo5a.js → quadrantDiagram-AXDQQJYC-ihH8znBv.js} +1 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-PRBiHoJx.js +1 -0
- ksadk/server/static/assets/railroad-74A4TZTK-BCJ-XMRJ.js +1 -0
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-Bbttj0Jz.js +1 -0
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-Bo18264J.js +1 -0
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-xZDJTFLD.js +1 -0
- ksadk/server/static/assets/{railroadDiagram-O6MQD6OU-BTAob2wg.js → railroadDiagram-O6MQD6OU-DD9lFfXo.js} +1 -1
- ksadk/server/static/assets/{requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js → requirementDiagram-EFPCY7ZU-CGn93Iyb.js} +1 -1
- ksadk/server/static/assets/{sankeyDiagram-P5KCCOFB-DeaTWkur.js → sankeyDiagram-P5KCCOFB-BuyjrHuW.js} +1 -1
- ksadk/server/static/assets/{sequenceDiagram-WJ2MYXX4-gFQYrsOd.js → sequenceDiagram-WJ2MYXX4-D-Iw-30A.js} +1 -1
- ksadk/server/static/assets/{sizeCapture-X5ZJPWSS-pGQzddMB.js → sizeCapture-X5ZJPWSS-B0EHLwrD.js} +1 -1
- ksadk/server/static/assets/{stateDiagram-HBIQ2CUA-DmpYOZt1.js → stateDiagram-HBIQ2CUA-k9Zyg69R.js} +1 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-tUEVnq9-.js +1 -0
- ksadk/server/static/assets/{swimlanes-XN3QIQJK-BfuSAsrr.js → swimlanes-XN3QIQJK-D2BewKmp.js} +1 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-CGBmsrCQ.js +8 -0
- ksadk/server/static/assets/{timeline-definition-24CTP7MA-CgJwrrxf.js → timeline-definition-24CTP7MA-czSzsYbz.js} +1 -1
- ksadk/server/static/assets/treeView-Q6P3EWNA-CrEvfC8M.js +1 -0
- ksadk/server/static/assets/treemap-WGGIJYW6-D1TmShtn.js +1 -0
- ksadk/server/static/assets/{vennDiagram-4TSXK5OY-CBSAgXDd.js → vennDiagram-4TSXK5OY-BJF_qZLF.js} +1 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-0gZiSyL0.js +1 -0
- ksadk/server/static/assets/{wardleyDiagram-VM6X3IG4-013TZ2JZ.js → wardleyDiagram-VM6X3IG4-BfwUuJpr.js} +1 -1
- ksadk/server/static/assets/{xychartDiagram-S5SC5T6Z-u6Frp8xp.js → xychartDiagram-S5SC5T6Z-Ci6Nsp4p.js} +1 -1
- ksadk/server/static/index.html +2 -2
- ksadk/server/static/ui-source.json +6 -6
- ksadk/sessions/_postgres_history_backfill.py +80 -0
- ksadk/sessions/_postgres_schema.py +117 -0
- ksadk/sessions/_postgres_tables.py +6 -0
- ksadk/sessions/base.py +24 -0
- ksadk/sessions/history_tool_refs.py +244 -0
- ksadk/sessions/in_memory.py +42 -0
- ksadk/sessions/local_service.py +78 -0
- ksadk/sessions/model_history.py +20 -0
- ksadk/sessions/postgres_service.py +215 -19
- ksadk/sessions/resilient.py +24 -0
- ksadk/skills/mcp_server/server.py +239 -217
- ksadk/studio/contracts.py +8 -0
- ksadk/studio/mcp_runtime.py +23 -8
- ksadk/studio/native_mcp_disclosure.py +8 -6
- ksadk/studio/native_mcp_tool_port.py +3 -1
- ksadk/studio/native_memory_context.py +10 -8
- ksadk/studio/native_product.py +3 -4
- ksadk/studio/plugin_composition.py +8 -1
- ksadk/studio/plugin_native_activation.py +4 -2
- ksadk/studio/plugin_runtime.py +9 -0
- ksadk/studio/service.py +2 -0
- ksadk/studio/static/assets/{ChannelsPage-Do_mRmVu.js → ChannelsPage-Ot9iV_QP.js} +1 -1
- ksadk/studio/static/assets/{CodeBlock-DMIf4h33-CsO7rJKv.js → CodeBlock-DMIf4h33-Cfs6se0v.js} +1 -1
- ksadk/studio/static/assets/{MathMessageMarkdown-BesSeCYl-CiB60plG.js → MathMessageMarkdown-BesSeCYl-BIBDiQAl.js} +1 -1
- ksadk/studio/static/assets/{MessageMarkdown-CwMTvgFj-BzEmQkHH.js → MessageMarkdown-CwMTvgFj-CWM4n-9K.js} +2 -2
- ksadk/studio/static/assets/{OfficialA2uiRenderer-DI49Kpxu-BBxfdj3P.js → OfficialA2uiRenderer-DI49Kpxu-BZSumE9D.js} +1 -1
- ksadk/studio/static/assets/{TeamsPage-qNVYpcox.js → TeamsPage-CVOpMIMf.js} +2 -2
- ksadk/studio/static/assets/index-CW1D-Kqg.css +2 -0
- ksadk/studio/static/assets/index-DMexeQ1-.js +1155 -0
- ksadk/studio/static/index.html +3 -3
- ksadk/studio/static/ui-source.json +6 -6
- ksadk/tracing/setup.py +53 -3
- ksadk/tunnel/__init__.py +37 -0
- ksadk/tunnel/connector.py +384 -0
- ksadk/tunnel/discovery.py +107 -0
- ksadk/tunnel/failure.py +168 -0
- ksadk/tunnel/http_tools.py +100 -0
- ksadk/tunnel/langgraph.py +125 -0
- ksadk/tunnel/middleware.py +28 -0
- ksadk/tunnel/peers.py +872 -0
- ksadk/tunnel/protocol.py +97 -0
- ksadk/tunnel/registry.py +306 -0
- ksadk/tunnel/runtime.py +147 -0
- ksadk/tunnel/server.py +201 -0
- ksadk/tunnel/services.py +366 -0
- ksadk/tunnel/toolset.py +78 -0
- ksadk/version.py +1 -1
- ksadk_runtime_common/memory_backend/providers/mem0.py +20 -0
- ksadk/server/static/assets/architecture-7GRP2DOG-CFWjFkDL.js +0 -1
- ksadk/server/static/assets/channel-D6Dp_l74.js +0 -1
- ksadk/server/static/assets/chunk-2Q5K7J3B-CwmjhFYK.js +0 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +0 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-CBZRVuc4.js +0 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +0 -1
- ksadk/server/static/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +0 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-BUWSkncI.js +0 -1
- ksadk/server/static/assets/index-4g1ndaxW.js +0 -1132
- ksadk/server/static/assets/index-DEVfafsU.css +0 -2
- ksadk/server/static/assets/info-A6RAGUB7-CzJ_YrOs.js +0 -1
- ksadk/server/static/assets/packet-AYTQ26CC-CXoos6fx.js +0 -1
- ksadk/server/static/assets/pie-WAS4IAKB-CjF9NoIt.js +0 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-BQGWs9nw.js +0 -1
- ksadk/server/static/assets/railroad-74A4TZTK-B6znvLUK.js +0 -1
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +0 -1
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +0 -1
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +0 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +0 -8
- ksadk/server/static/assets/treeView-Q6P3EWNA-DtMdDH8N.js +0 -1
- ksadk/server/static/assets/treemap-WGGIJYW6-VoU8QtLZ.js +0 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-YWSRB0Zm.js +0 -1
- ksadk/studio/static/assets/index-Cp9Unfkn.css +0 -2
- ksadk/studio/static/assets/index-HepnaEeR.js +0 -1152
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/WHEEL +0 -0
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/top_level.txt +0 -0
ksadk/runtime/factory.py
CHANGED
|
@@ -45,15 +45,21 @@ from ksadk.runtime.launch import RuntimeLaunchContext
|
|
|
45
45
|
def _create_harness(context: RuntimeLaunchContext) -> RuntimeAdapter:
|
|
46
46
|
"""Create the managed KsADK Harness adapter from an immutable launch manifest."""
|
|
47
47
|
|
|
48
|
+
from ksadk.harness.service_runtime import harness_service_from_env
|
|
49
|
+
|
|
50
|
+
config = dict(context.config)
|
|
51
|
+
prompt = str(config.get("prompt") or config.get("base_instructions") or "").strip()
|
|
52
|
+
model = str(config.get("model") or "").strip()
|
|
53
|
+
service = harness_service_from_env(instructions=prompt, model=model or None)
|
|
54
|
+
if service is not None:
|
|
55
|
+
return service
|
|
56
|
+
|
|
48
57
|
import re
|
|
49
58
|
|
|
50
59
|
from ksadk.harness.managed_runtime import ManagedHarnessRuntimeAdapter
|
|
51
60
|
from ksadk.harness.reasoner import ModelGatewayHarnessReasoner
|
|
52
61
|
from ksadk.harness.spec import HarnessSpec, ModelBinding, PromptSpec
|
|
53
62
|
|
|
54
|
-
config = dict(context.config)
|
|
55
|
-
prompt = str(config.get("prompt") or config.get("base_instructions") or "").strip()
|
|
56
|
-
model = str(config.get("model") or "").strip()
|
|
57
63
|
if not prompt:
|
|
58
64
|
raise ValueError("harness runtime requires prompt/base_instructions")
|
|
59
65
|
if not model:
|
|
@@ -180,11 +186,17 @@ def _create_framework_runner(context: RuntimeLaunchContext, runtime_type: str) -
|
|
|
180
186
|
|
|
181
187
|
|
|
182
188
|
def _create_adk(context: RuntimeLaunchContext) -> RuntimeAdapter:
|
|
183
|
-
|
|
189
|
+
adapter = ADKRuntimeAdapter(_create_framework_runner(context, "adk"))
|
|
190
|
+
if context.services.tunnel_binding is not None:
|
|
191
|
+
adapter.configure_tunnel(context.services.tunnel_binding)
|
|
192
|
+
return adapter
|
|
184
193
|
|
|
185
194
|
|
|
186
195
|
def _create_langgraph(context: RuntimeLaunchContext) -> RuntimeAdapter:
|
|
187
|
-
|
|
196
|
+
adapter = LangGraphRuntimeAdapter(_create_framework_runner(context, "langgraph"))
|
|
197
|
+
if context.services.tunnel_binding is not None:
|
|
198
|
+
adapter.configure_tunnel(context.services.tunnel_binding)
|
|
199
|
+
return adapter
|
|
188
200
|
|
|
189
201
|
|
|
190
202
|
def build_default_runtime_registry(
|
|
@@ -41,6 +41,11 @@ class ADKRuntimeAdapter(RunnerRuntimeAdapter):
|
|
|
41
41
|
def __init__(self, runner: BaseRunner) -> None:
|
|
42
42
|
super().__init__(runner, runtime_type="adk")
|
|
43
43
|
|
|
44
|
+
def configure_tunnel(self, binding) -> None:
|
|
45
|
+
from ksadk.tunnel.runtime import bind_runner
|
|
46
|
+
|
|
47
|
+
bind_runner(self._runner, binding)
|
|
48
|
+
|
|
44
49
|
async def restore_run_record(self, handle: RunHandle, record: "RunRecord") -> None:
|
|
45
50
|
"""Rebuild private request context after native attachment has succeeded.
|
|
46
51
|
|
|
@@ -152,6 +157,11 @@ class LangGraphRuntimeAdapter(NativeLangGraphInteractionMixin, RunnerRuntimeAdap
|
|
|
152
157
|
def __init__(self, runner: BaseRunner) -> None:
|
|
153
158
|
super().__init__(runner, runtime_type="langgraph")
|
|
154
159
|
|
|
160
|
+
def configure_tunnel(self, binding) -> None:
|
|
161
|
+
from ksadk.tunnel.runtime import bind_runner
|
|
162
|
+
|
|
163
|
+
bind_runner(self._runner, binding)
|
|
164
|
+
|
|
155
165
|
async def durable_restore(self, handle: RunHandle) -> RunHandle:
|
|
156
166
|
# Recovery's adapter factory creates a cold runner, independently of
|
|
157
167
|
# the deployment capability probe. Bind its saver before checking the
|
|
@@ -87,7 +87,24 @@ def fresh_checkpoint_view(config: Any, saved: Any) -> Any:
|
|
|
87
87
|
pending = list(saved.pending_writes or [])
|
|
88
88
|
if any(channel == "__interrupt__" for _, channel, _ in pending):
|
|
89
89
|
return saved
|
|
90
|
-
|
|
90
|
+
# A custom graph can append other messages before it records a tool receipt.
|
|
91
|
+
# Match each receipt to the most recent preceding call with that provider ID.
|
|
92
|
+
call_positions = {}
|
|
93
|
+
results_by_call = {}
|
|
94
|
+
result_positions = set()
|
|
95
|
+
changed = False
|
|
96
|
+
for index, message in enumerate(messages):
|
|
97
|
+
if isinstance(message, AIMessage) and message.tool_calls:
|
|
98
|
+
for call in message.tool_calls:
|
|
99
|
+
call_positions[call.get("id")] = index
|
|
100
|
+
elif isinstance(message, ToolMessage) and message.tool_call_id in call_positions:
|
|
101
|
+
owner = call_positions[message.tool_call_id]
|
|
102
|
+
results = results_by_call.setdefault(owner, [])
|
|
103
|
+
results.append(message)
|
|
104
|
+
result_positions.add(index)
|
|
105
|
+
# Strict providers require the receipts immediately after their AI message.
|
|
106
|
+
if index != owner + len(results):
|
|
107
|
+
changed = True
|
|
91
108
|
pending_results = {}
|
|
92
109
|
updated_pending = []
|
|
93
110
|
for task, channel, value in pending:
|
|
@@ -107,19 +124,23 @@ def fresh_checkpoint_view(config: Any, saved: Any) -> Any:
|
|
|
107
124
|
updated_pending.append((task, channel, value))
|
|
108
125
|
|
|
109
126
|
repaired = []
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
for index, message in enumerate(messages):
|
|
128
|
+
if index in result_positions:
|
|
129
|
+
continue # Emitted with the original call, in receipt order.
|
|
112
130
|
repaired.append(message)
|
|
113
131
|
if not isinstance(message, AIMessage):
|
|
114
132
|
continue
|
|
133
|
+
results = results_by_call.get(index, ())
|
|
134
|
+
repaired.extend(results)
|
|
135
|
+
answered = {result.tool_call_id for result in results}
|
|
115
136
|
for call in message.tool_calls:
|
|
116
137
|
call_id = call.get("id")
|
|
117
|
-
if not call_id or call_id in
|
|
138
|
+
if not call_id or call_id in answered:
|
|
118
139
|
continue
|
|
119
|
-
result = pending_results.get(call_id)
|
|
140
|
+
result = pending_results.get(call_id) if index == call_positions[call_id] else None
|
|
120
141
|
if result is None:
|
|
121
142
|
identity = hashlib.sha256(
|
|
122
|
-
f"{saved.checkpoint['id']}:{call_id}".encode()
|
|
143
|
+
f"{saved.checkpoint['id']}:{index}:{call_id}".encode()
|
|
123
144
|
).hexdigest()
|
|
124
145
|
result = ToolMessage(
|
|
125
146
|
id=f"ksadk-interrupted-{identity}", tool_call_id=call_id,
|
|
@@ -135,7 +156,7 @@ def fresh_checkpoint_view(config: Any, saved: Any) -> Any:
|
|
|
135
156
|
}},
|
|
136
157
|
)
|
|
137
158
|
repaired.append(result)
|
|
138
|
-
|
|
159
|
+
answered.add(call_id)
|
|
139
160
|
changed = True
|
|
140
161
|
if not changed:
|
|
141
162
|
return saved
|
ksadk/runtime/launch.py
CHANGED
|
@@ -26,6 +26,8 @@ class RuntimeServices:
|
|
|
26
26
|
runner_factory: Callable[[Any, str], Any] | None = None
|
|
27
27
|
# Process-owned dependency; never serialized into user/runtime config.
|
|
28
28
|
managed_a2a_bootstrap: Any | None = None
|
|
29
|
+
# App-owned MCP tunnel registry and immutable deployment identity.
|
|
30
|
+
tunnel_binding: Any | None = None
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
@dataclass(frozen=True)
|
ksadk/server/factory.py
CHANGED
|
@@ -239,6 +239,7 @@ class RuntimeAppConfig:
|
|
|
239
239
|
teams_host_factory: Any | None = None,
|
|
240
240
|
a2ui_catalog_registry: Any | None = None,
|
|
241
241
|
local_mcp_oauth: bool = False,
|
|
242
|
+
auto_tracing: bool = True,
|
|
242
243
|
) -> None:
|
|
243
244
|
self.runtime_type = runtime_type
|
|
244
245
|
self.route_groups: set[str] = (
|
|
@@ -260,6 +261,8 @@ class RuntimeAppConfig:
|
|
|
260
261
|
self.a2ui_catalog_registry = a2ui_catalog_registry
|
|
261
262
|
# Composition-only switch. Never populated from Agent YAML or env.
|
|
262
263
|
self.local_mcp_oauth = local_mcp_oauth
|
|
264
|
+
# Composition-only opt-out for callers such as `ksadk run --no-trace`.
|
|
265
|
+
self.auto_tracing = auto_tracing
|
|
263
266
|
|
|
264
267
|
|
|
265
268
|
# ---------------------------------------------------------------------------
|
|
@@ -380,6 +383,35 @@ def _is_agent_execution_path(path: str, method: str) -> bool:
|
|
|
380
383
|
return False
|
|
381
384
|
|
|
382
385
|
|
|
386
|
+
def _setup_runtime_tracing() -> None:
|
|
387
|
+
"""Initialize configured OTLP tracing before composing a Runtime app.
|
|
388
|
+
|
|
389
|
+
Unconfigured processes and application-owned providers stay untouched.
|
|
390
|
+
The existing setup function serializes initialization and owns exporters.
|
|
391
|
+
"""
|
|
392
|
+
if os.getenv("OTEL_SDK_DISABLED", "").strip().lower() == "true":
|
|
393
|
+
return
|
|
394
|
+
if not any(os.getenv(name, "").strip() for name in (
|
|
395
|
+
"OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
|
|
396
|
+
"CLOUD_MONITOR_OTLP_ENDPOINT", "CLOUD_MONITOR_OTLP_TRACES_ENDPOINT",
|
|
397
|
+
"CLOUD_MONITOR_OTLP_HEADERS", "CLOUD_MONITOR_OTLP_TRACES_HEADERS",
|
|
398
|
+
"CLOUD_MONITOR_APP_KEY",
|
|
399
|
+
)):
|
|
400
|
+
return
|
|
401
|
+
try:
|
|
402
|
+
from opentelemetry import trace
|
|
403
|
+
|
|
404
|
+
# Includes explicit SDK setup, routed tracing and OTel auto-instrumentation.
|
|
405
|
+
# Do not replace a user's provider or attach a second static exporter.
|
|
406
|
+
if not isinstance(trace.get_tracer_provider(), trace.ProxyTracerProvider):
|
|
407
|
+
return
|
|
408
|
+
from ksadk.tracing import setup_tracing
|
|
409
|
+
|
|
410
|
+
setup_tracing()
|
|
411
|
+
except Exception:
|
|
412
|
+
logger.warning("Runtime tracing initialization failed; continuing without automatic tracing", exc_info=True)
|
|
413
|
+
|
|
414
|
+
|
|
383
415
|
def create_runtime_app(
|
|
384
416
|
config: RuntimeAppConfig,
|
|
385
417
|
configure: Optional[ConfigureApp] = None,
|
|
@@ -399,6 +431,13 @@ def create_runtime_app(
|
|
|
399
431
|
from fastapi.middleware.cors import CORSMiddleware
|
|
400
432
|
from fastapi.responses import Response
|
|
401
433
|
|
|
434
|
+
from ksadk.tunnel.runtime import DeferredTunnel, configure_app_tunnel
|
|
435
|
+
|
|
436
|
+
if config.auto_tracing:
|
|
437
|
+
_setup_runtime_tracing()
|
|
438
|
+
|
|
439
|
+
config, tunnel_binding = configure_app_tunnel(config)
|
|
440
|
+
|
|
402
441
|
if config.a2ui_catalog_registry is not None:
|
|
403
442
|
from ksadk.a2ui.registry import A2uiCatalogRegistry
|
|
404
443
|
|
|
@@ -430,6 +469,9 @@ def create_runtime_app(
|
|
|
430
469
|
)
|
|
431
470
|
from ksadk.runtime.factory import kernel_start_request_defaults
|
|
432
471
|
|
|
472
|
+
if tunnel_binding is not None:
|
|
473
|
+
await tunnel_binding.start()
|
|
474
|
+
|
|
433
475
|
adapter_provider = _kernel_adapter_provider(config)
|
|
434
476
|
from ksadk.kernel.session_storage import postgres_kernel_enabled
|
|
435
477
|
if teams_host is not None:
|
|
@@ -455,6 +497,8 @@ def create_runtime_app(
|
|
|
455
497
|
**({"before_start": teams_host.before_start} if teams_host is not None else {}),
|
|
456
498
|
)
|
|
457
499
|
except BaseException:
|
|
500
|
+
if tunnel_binding is not None:
|
|
501
|
+
await tunnel_binding.close()
|
|
458
502
|
if teams_host is not None:
|
|
459
503
|
await teams_host.close()
|
|
460
504
|
_kernel_ingress.set_teams_ingress_gate(None)
|
|
@@ -490,6 +534,8 @@ def create_runtime_app(
|
|
|
490
534
|
await state.a2a_bootstrap.start()
|
|
491
535
|
yield
|
|
492
536
|
finally:
|
|
537
|
+
if tunnel_binding is not None:
|
|
538
|
+
await tunnel_binding.close()
|
|
493
539
|
if state.a2a_bootstrap is not None:
|
|
494
540
|
await state.a2a_bootstrap.stop()
|
|
495
541
|
if state.local_interactions is not None:
|
|
@@ -515,6 +561,15 @@ def create_runtime_app(
|
|
|
515
561
|
)
|
|
516
562
|
state.app = app
|
|
517
563
|
app.state.runtime = state
|
|
564
|
+
if tunnel_binding is not None:
|
|
565
|
+
from ksadk.tunnel.server import mount_tunnel
|
|
566
|
+
|
|
567
|
+
if isinstance(tunnel_binding, DeferredTunnel):
|
|
568
|
+
from ksadk.tunnel.server import install_connector_fallback
|
|
569
|
+
|
|
570
|
+
install_connector_fallback(app, tunnel_binding)
|
|
571
|
+
else:
|
|
572
|
+
mount_tunnel(app, policies=[tunnel_binding.policy], registry=tunnel_binding.registry)
|
|
518
573
|
if teams_host is not None:
|
|
519
574
|
from ksadk.kernel.teams_host_http import create_teams_host_router
|
|
520
575
|
|
|
@@ -909,7 +964,9 @@ def _wire_agui_if_enabled(app: FastAPI, state: RuntimeAppState, config: RuntimeA
|
|
|
909
964
|
if config.kernel_adapter_provider is not None or config.a2a_runtime_adapter is not None
|
|
910
965
|
else lambda: state.executor.capability_adapter(state.launch_context)
|
|
911
966
|
), launch_context=state.launch_context,
|
|
912
|
-
|
|
967
|
+
# Startup/recovery may run outside an HTTP request, or while a
|
|
968
|
+
# different app is bound. This runtime owns this app's storage.
|
|
969
|
+
session_service=state.resolve_session_service,
|
|
913
970
|
agent_name=agui_cfg.agent_name,
|
|
914
971
|
on_ready=state.persistence_capability.invalidate,
|
|
915
972
|
adapter_owned=(config.kernel_adapter_provider is not None
|
ksadk/server/routes/common.py
CHANGED
|
@@ -42,6 +42,7 @@ from ..invocation_identity import (
|
|
|
42
42
|
trusted_invocation_identity_headers,
|
|
43
43
|
)
|
|
44
44
|
from . import dependencies as deps
|
|
45
|
+
from .harness_service_view import register_harness_service_view
|
|
45
46
|
from .routers import health_meta_router
|
|
46
47
|
|
|
47
48
|
logger = logging.getLogger(__name__)
|
|
@@ -146,6 +147,7 @@ def _register_integrated_routers(app: FastAPI, state: RuntimeAppState) -> None:
|
|
|
146
147
|
goal-01:由模块级 ``app.include_router(...)`` 改为在 factory 的 configure
|
|
147
148
|
回调里调用,普通 app 与 HarnessApp 各自装配,互不共享。
|
|
148
149
|
"""
|
|
150
|
+
register_harness_service_view(app)
|
|
149
151
|
app.include_router(
|
|
150
152
|
create_workspace_files_router(
|
|
151
153
|
root_getter=_workspace_root_dir,
|
ksadk/server/routes/control.py
CHANGED
|
@@ -4,7 +4,6 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import json
|
|
7
|
-
import os
|
|
8
7
|
import time
|
|
9
8
|
import uuid
|
|
10
9
|
from collections.abc import AsyncIterator, Mapping
|
|
@@ -37,6 +36,7 @@ from ..invocation_identity import (
|
|
|
37
36
|
from . import dependencies as deps
|
|
38
37
|
from .checkpoint_resolution import _find_session_checkpoint
|
|
39
38
|
from .common import _action_response
|
|
39
|
+
from .local_kernel_control import resolve_local_responses_run_id
|
|
40
40
|
from .models import (
|
|
41
41
|
_MAX_PREVIEW_TOOL_RECEIPTS,
|
|
42
42
|
_RUN_TERMINAL_STATUSES,
|
|
@@ -539,11 +539,16 @@ async def subscribe_run_events_action(
|
|
|
539
539
|
invocation_identity=invocation_identity,
|
|
540
540
|
history_only=True,
|
|
541
541
|
)
|
|
542
|
+
stored_run_id = invocation_id
|
|
542
543
|
if not await _session_contains_invocation(service, session_id, invocation_id):
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
544
|
+
# The accepted Inbox command can identify the Run even before the
|
|
545
|
+
# worker writes its first event. Reconnect must not submit it again.
|
|
546
|
+
stored_run_id = await resolve_local_responses_run_id(session_id, invocation_id)
|
|
547
|
+
if stored_run_id is None:
|
|
548
|
+
raise HTTPException(
|
|
549
|
+
status_code=409,
|
|
550
|
+
detail="InvocationId does not belong to SessionId",
|
|
551
|
+
)
|
|
547
552
|
|
|
548
553
|
async def event_generator() -> AsyncIterator[str]:
|
|
549
554
|
last_seq_id = int(AfterSeqId or 0)
|
|
@@ -561,19 +566,30 @@ async def subscribe_run_events_action(
|
|
|
561
566
|
service,
|
|
562
567
|
session_id,
|
|
563
568
|
after_seq_id=last_seq_id,
|
|
564
|
-
invocation_id=
|
|
569
|
+
invocation_id=stored_run_id,
|
|
565
570
|
)
|
|
566
571
|
for event in events:
|
|
567
572
|
last_seq_id = max(last_seq_id, event.seq_id)
|
|
568
|
-
if event.invocation_id !=
|
|
573
|
+
if event.invocation_id != stored_run_id:
|
|
569
574
|
continue
|
|
570
575
|
payload = _event_to_action_payload(event)
|
|
576
|
+
if stored_run_id != invocation_id:
|
|
577
|
+
# Only the compatibility envelope uses the request ID.
|
|
578
|
+
# Canonical event content retains the Kernel Run ID.
|
|
579
|
+
payload["InvocationId"] = invocation_id
|
|
571
580
|
yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
|
|
572
581
|
last_heartbeat_at = time.monotonic()
|
|
582
|
+
runtime_event = (event.content or {}).get("runtime_event")
|
|
573
583
|
if (
|
|
574
584
|
event.event_type == "run_status"
|
|
575
585
|
and str((event.content or {}).get("status") or "").strip().lower()
|
|
576
586
|
in _RUN_TERMINAL_STATUSES
|
|
587
|
+
) or (
|
|
588
|
+
event.event_type in {
|
|
589
|
+
"run.completed", "run.failed", "run.canceled", "run.interrupted",
|
|
590
|
+
}
|
|
591
|
+
and isinstance(runtime_event, Mapping)
|
|
592
|
+
and not runtime_event.get("parent_scope_id")
|
|
577
593
|
):
|
|
578
594
|
yield "data: [DONE]\n\n"
|
|
579
595
|
return
|
|
@@ -583,7 +599,7 @@ async def subscribe_run_events_action(
|
|
|
583
599
|
latest_status = await _latest_invocation_status(
|
|
584
600
|
service,
|
|
585
601
|
session_id,
|
|
586
|
-
|
|
602
|
+
stored_run_id,
|
|
587
603
|
)
|
|
588
604
|
last_terminal_check_at = now
|
|
589
605
|
if latest_status in _RUN_TERMINAL_STATUSES:
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Same-origin presentation proxy; the browser never receives service credentials."""
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from fastapi import FastAPI, HTTPException, Request, Response
|
|
5
|
+
|
|
6
|
+
from ksadk.harness.service_presentation import ENGINE_VIEW_PATH, VIEW_HASH
|
|
7
|
+
from ksadk.harness.service_runtime import harness_service_from_env
|
|
8
|
+
|
|
9
|
+
_VIEW_HEADERS = {
|
|
10
|
+
"cache-control": "private, max-age=31536000, immutable",
|
|
11
|
+
"content-security-policy": (
|
|
12
|
+
"default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; "
|
|
13
|
+
"img-src data:; sandbox allow-scripts"
|
|
14
|
+
),
|
|
15
|
+
"x-content-type-options": "nosniff",
|
|
16
|
+
"referrer-policy": "no-referrer",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def register_harness_service_view(app: FastAPI) -> None:
|
|
21
|
+
@app.api_route(
|
|
22
|
+
ENGINE_VIEW_PATH + "/{sha256}", methods=["GET", "HEAD"], include_in_schema=False
|
|
23
|
+
)
|
|
24
|
+
async def get_view(request: Request, sha256: str) -> Response:
|
|
25
|
+
if not VIEW_HASH.fullmatch(sha256):
|
|
26
|
+
raise HTTPException(status_code=404)
|
|
27
|
+
try:
|
|
28
|
+
service = harness_service_from_env()
|
|
29
|
+
html = await service.view_html(sha256) if service is not None else None
|
|
30
|
+
except (httpx.HTTPError, ValueError, RuntimeError) as error:
|
|
31
|
+
raise HTTPException(status_code=502, detail="Harness view unavailable") from error
|
|
32
|
+
if html is None:
|
|
33
|
+
raise HTTPException(status_code=404)
|
|
34
|
+
return Response(
|
|
35
|
+
content=b"" if request.method == "HEAD" else html,
|
|
36
|
+
media_type="text/html",
|
|
37
|
+
headers=_VIEW_HEADERS,
|
|
38
|
+
)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Exclusive keyset paging of immutable session events inside or across turns."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import base64
|
|
5
|
+
import binascii
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
from fastapi import HTTPException
|
|
9
|
+
|
|
10
|
+
from ksadk.sessions.base import SessionEventQuery
|
|
11
|
+
from ksadk.sessions.errors import HistoryReloadRequired
|
|
12
|
+
from ksadk.sessions.history_tool_refs import DeferredToolEvent, tool_facts, tool_ref
|
|
13
|
+
|
|
14
|
+
from .projection import _event_to_action_payload
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _next_cursor(epoch: str, snapshot: int, boundary: int, forward: bool) -> str:
|
|
18
|
+
# Epoch includes the session and its durable source (or process-local identity).
|
|
19
|
+
# The route independently checks session ownership on every request.
|
|
20
|
+
payload = json.dumps([1, epoch, snapshot, boundary, forward], separators=(",", ":"))
|
|
21
|
+
return base64.urlsafe_b64encode(payload.encode()).decode()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _position(request, epoch: str, newest_seq: int) -> tuple[int, int, bool]:
|
|
25
|
+
if request.ItemCursor is not None:
|
|
26
|
+
try:
|
|
27
|
+
value = json.loads(base64.b64decode(request.ItemCursor, altchars=b"-_", validate=True))
|
|
28
|
+
version, source, snapshot, boundary, forward = value
|
|
29
|
+
if (type(version) is not int or version != 1 or type(source) is not str
|
|
30
|
+
or type(snapshot) is not int or type(boundary) is not int
|
|
31
|
+
or type(forward) is not bool or not 0 < boundary <= snapshot):
|
|
32
|
+
raise ValueError
|
|
33
|
+
except (ValueError, TypeError, binascii.Error, RecursionError):
|
|
34
|
+
raise HTTPException(status_code=422, detail="Invalid item cursor") from None
|
|
35
|
+
if (source != epoch or snapshot > newest_seq
|
|
36
|
+
or request.SnapshotSeqId not in (None, snapshot)):
|
|
37
|
+
raise HistoryReloadRequired("Item cursor snapshot or history source changed")
|
|
38
|
+
return snapshot, boundary, forward
|
|
39
|
+
|
|
40
|
+
snapshot = newest_seq if request.SnapshotSeqId is None else request.SnapshotSeqId
|
|
41
|
+
if snapshot > newest_seq:
|
|
42
|
+
raise HistoryReloadRequired("Item snapshot is ahead of the current source")
|
|
43
|
+
if request.AfterSeqId is not None:
|
|
44
|
+
if request.AfterSeqId > snapshot:
|
|
45
|
+
raise HistoryReloadRequired("Resume position is ahead of the snapshot")
|
|
46
|
+
# When both bounds are provided the upper bound also fixes the page chain.
|
|
47
|
+
if request.BeforeSeqId is not None:
|
|
48
|
+
snapshot = min(snapshot, request.BeforeSeqId - 1)
|
|
49
|
+
return snapshot, request.AfterSeqId, True
|
|
50
|
+
return snapshot, min(request.BeforeSeqId or snapshot + 1, snapshot + 1), False
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
_PAGE_BYTES = 512 * 1024
|
|
54
|
+
_CHUNK_CHARACTERS = 32 * 1024
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _wire_bytes(value: dict) -> int:
|
|
58
|
+
return len(json.dumps(value, ensure_ascii=False, separators=(",", ":")).encode())
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def read_item_page(request, service, epoch, newest_seq, tenant_id):
|
|
62
|
+
from ksadk.kernel.bootstrap import get_agent_kernel_runtime
|
|
63
|
+
from ksadk.kernel.history_projection import item_inbox_chunks, item_input_annotations
|
|
64
|
+
|
|
65
|
+
snapshot, boundary, forward = _position(request, epoch, newest_seq)
|
|
66
|
+
common = {
|
|
67
|
+
"SessionId": request.SessionId, "HistoryView": "items-v1",
|
|
68
|
+
"SnapshotSeqId": snapshot, "HistoryEpoch": epoch, "DataSource": "runtime",
|
|
69
|
+
"CursorSource": "runtime", "CursorCompatibleWithRuntime": True, "Degraded": False,
|
|
70
|
+
"SessionContractVersion": 2,
|
|
71
|
+
}
|
|
72
|
+
if request.ContentSeqId is not None:
|
|
73
|
+
if request.ContentPart == "inbox":
|
|
74
|
+
seq = request.ContentSeqId
|
|
75
|
+
manifest = await service.get_history_item_manifest_window(SessionEventQuery(
|
|
76
|
+
session_ids=[request.SessionId], after_seq_id=seq - 1, before_seq_id=seq + 1,
|
|
77
|
+
from_start=True, order_by_seq=True, limit=1,
|
|
78
|
+
), byte_limit=_PAGE_BYTES)
|
|
79
|
+
chunks = await item_inbox_chunks(
|
|
80
|
+
[_event_to_action_payload(event) for event, deferred in manifest if not deferred],
|
|
81
|
+
runtime=get_agent_kernel_runtime(), session_id=request.SessionId,
|
|
82
|
+
tenant_id=tenant_id,
|
|
83
|
+
offset=request.ContentOffset or 0, limit=_CHUNK_CHARACTERS,
|
|
84
|
+
)
|
|
85
|
+
chunk = chunks.get(seq)
|
|
86
|
+
else:
|
|
87
|
+
chunk = await service.get_history_item_content(
|
|
88
|
+
request.SessionId, request.ContentSeqId, request.ContentOffset or 0,
|
|
89
|
+
_CHUNK_CHARACTERS,
|
|
90
|
+
)
|
|
91
|
+
if chunk is None:
|
|
92
|
+
raise HistoryReloadRequired("History item unavailable in this snapshot")
|
|
93
|
+
content, next_offset = chunk
|
|
94
|
+
if not content:
|
|
95
|
+
raise HTTPException(status_code=422, detail="Content offset outside item")
|
|
96
|
+
return {**common, "ContentSeqId": request.ContentSeqId, "ContentChunk": content,
|
|
97
|
+
"NextContentOffset": next_offset,
|
|
98
|
+
**({"ContentPart": request.ContentPart} if request.ContentPart else {})}
|
|
99
|
+
before = snapshot + 1 if forward else boundary
|
|
100
|
+
query = SessionEventQuery(
|
|
101
|
+
session_ids=[request.SessionId], after_seq_id=boundary if forward else None,
|
|
102
|
+
before_seq_id=before, limit=request.Limit, order_by_seq=True, from_start=forward,
|
|
103
|
+
)
|
|
104
|
+
manifest = await service.get_history_item_manifest_window(query, byte_limit=_PAGE_BYTES)
|
|
105
|
+
candidates = []
|
|
106
|
+
for event, deferred in manifest:
|
|
107
|
+
header = {
|
|
108
|
+
"EventId": event.id, "SessionId": event.session_id, "SeqId": event.seq_id,
|
|
109
|
+
"Author": event.author, "Timestamp": event.timestamp, "EventType": event.event_type,
|
|
110
|
+
"InvocationId": event.invocation_id,
|
|
111
|
+
}
|
|
112
|
+
payload = header if deferred else _event_to_action_payload(event)
|
|
113
|
+
# Legacy display text can duplicate a canonical field. Size the actual wire
|
|
114
|
+
# representation, keeping headroom for a verified inbox annotation.
|
|
115
|
+
if not deferred and _wire_bytes(payload) > _PAGE_BYTES - 16 * 1024:
|
|
116
|
+
deferred = True
|
|
117
|
+
payload = header
|
|
118
|
+
item = {
|
|
119
|
+
"ItemId": event.id, "InvocationId": payload.get("InvocationId"),
|
|
120
|
+
"SeqId": event.seq_id, "EventType": payload["EventType"], "Event": payload,
|
|
121
|
+
}
|
|
122
|
+
if deferred:
|
|
123
|
+
item["ContentRef"] = {"SeqId": event.seq_id}
|
|
124
|
+
ref = (event.tool_ref if isinstance(event, DeferredToolEvent) else
|
|
125
|
+
tool_ref(event.event_type, tool_facts(event.event_type, event.content, event.metadata)))
|
|
126
|
+
if ref:
|
|
127
|
+
item["ToolRef"] = ref
|
|
128
|
+
candidates.append(item)
|
|
129
|
+
annotations = await item_input_annotations(
|
|
130
|
+
[item["Event"] for item in candidates], runtime=get_agent_kernel_runtime(),
|
|
131
|
+
session_id=request.SessionId, tenant_id=tenant_id,
|
|
132
|
+
)
|
|
133
|
+
items = []
|
|
134
|
+
used = 0
|
|
135
|
+
for item in candidates if forward else reversed(candidates):
|
|
136
|
+
item.update(annotations.get(item["SeqId"], {}))
|
|
137
|
+
size = _wire_bytes(item) + 1
|
|
138
|
+
if items and used + size > _PAGE_BYTES:
|
|
139
|
+
break
|
|
140
|
+
items.append(item)
|
|
141
|
+
used += size
|
|
142
|
+
if not forward:
|
|
143
|
+
items.reverse()
|
|
144
|
+
next_cursor = None
|
|
145
|
+
if items:
|
|
146
|
+
edge = items[-1]["SeqId"] if forward else items[0]["SeqId"]
|
|
147
|
+
more = await service.has_events(
|
|
148
|
+
request.SessionId, after_seq_id=edge if forward else None,
|
|
149
|
+
before_seq_id=snapshot + 1 if forward else edge,
|
|
150
|
+
)
|
|
151
|
+
if more:
|
|
152
|
+
next_cursor = _next_cursor(epoch, snapshot, edge, forward)
|
|
153
|
+
return {
|
|
154
|
+
**common, "Items": items,
|
|
155
|
+
"NextItemCursor": next_cursor, "HasMore": next_cursor is not None,
|
|
156
|
+
"LatestSeqId": items[-1]["SeqId"] if items else (boundary if forward else 0),
|
|
157
|
+
}
|