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/tunnel/protocol.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Frame limits and errors for the streaming HTTP tunnel."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import math
|
|
7
|
+
import re
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
LOCAL_ERROR_CODES = frozenset(
|
|
12
|
+
{
|
|
13
|
+
"busy",
|
|
14
|
+
"forbidden",
|
|
15
|
+
"invalid_request",
|
|
16
|
+
"local_mcp_error",
|
|
17
|
+
"local_service_error",
|
|
18
|
+
"timeout",
|
|
19
|
+
"frame_too_large",
|
|
20
|
+
"too_many_tools",
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
VERSION = 2
|
|
25
|
+
_IDENTIFIER = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]{0,63}\Z")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class TunnelError(RuntimeError):
|
|
29
|
+
"""A sanitized tunnel failure; a failed call may already have taken effect."""
|
|
30
|
+
|
|
31
|
+
def __init__(self, code: str, *, indeterminate: bool = False):
|
|
32
|
+
self.code = code
|
|
33
|
+
self.indeterminate = indeterminate
|
|
34
|
+
super().__init__(f"Tool tunnel: {code}" + (" (outcome unknown)" if indeterminate else ""))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class IncompletePeerDiscovery(TunnelError):
|
|
38
|
+
"""No services were confirmed because one or more peers were unreachable."""
|
|
39
|
+
|
|
40
|
+
def __init__(self):
|
|
41
|
+
super().__init__("peer_discovery_unavailable")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class TunnelLimits:
|
|
46
|
+
max_frame_bytes: int = 1_048_576
|
|
47
|
+
max_response_bytes: int = 8_388_608
|
|
48
|
+
max_inflight: int = 32
|
|
49
|
+
max_services: int = 16
|
|
50
|
+
max_tools: int = 256
|
|
51
|
+
registration_timeout: float = 10.0
|
|
52
|
+
request_timeout: float = 60.0
|
|
53
|
+
send_timeout: float = 5.0
|
|
54
|
+
heartbeat_interval: float = 15.0
|
|
55
|
+
idle_timeout: float = 45.0
|
|
56
|
+
|
|
57
|
+
def __post_init__(self):
|
|
58
|
+
for name, value in vars(self).items():
|
|
59
|
+
if (
|
|
60
|
+
isinstance(value, bool)
|
|
61
|
+
or not isinstance(value, (int, float))
|
|
62
|
+
or not math.isfinite(value)
|
|
63
|
+
or value <= 0
|
|
64
|
+
or (name.startswith("max_") and not isinstance(value, int))
|
|
65
|
+
):
|
|
66
|
+
raise ValueError(f"{name} must be finite and positive (limits require integers)")
|
|
67
|
+
if self.idle_timeout <= self.heartbeat_interval:
|
|
68
|
+
raise ValueError("idle_timeout must exceed heartbeat_interval")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def identifier(value: Any, field: str) -> str:
|
|
72
|
+
if not isinstance(value, str) or not _IDENTIFIER.fullmatch(value):
|
|
73
|
+
raise ValueError(f"{field} must be a 1-64 character identifier")
|
|
74
|
+
return value
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def decode_request_body(body: bytes) -> str:
|
|
78
|
+
try:
|
|
79
|
+
return body.decode("utf-8")
|
|
80
|
+
except UnicodeDecodeError:
|
|
81
|
+
raise TunnelError("invalid_request") from None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def encode(frame: dict[str, Any], limits: TunnelLimits) -> str:
|
|
85
|
+
raw = json.dumps(frame, ensure_ascii=False, separators=(",", ":"), allow_nan=False)
|
|
86
|
+
if len(raw.encode("utf-8")) > limits.max_frame_bytes:
|
|
87
|
+
raise TunnelError("frame_too_large")
|
|
88
|
+
return raw
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def decode(raw: str, limits: TunnelLimits) -> dict[str, Any]:
|
|
92
|
+
if not isinstance(raw, str) or len(raw.encode("utf-8")) > limits.max_frame_bytes:
|
|
93
|
+
raise ValueError("invalid frame size or encoding")
|
|
94
|
+
frame = json.loads(raw, parse_constant=lambda _: (_ for _ in ()).throw(ValueError("NaN")))
|
|
95
|
+
if not isinstance(frame, dict):
|
|
96
|
+
raise ValueError("frame must be an object")
|
|
97
|
+
return frame
|
ksadk/tunnel/registry.py
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"""App-owned registrations and request correlation, never a process global registry."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import uuid
|
|
7
|
+
from contextlib import nullcontext
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
# The transport, response streams and MCP client must use the same backend,
|
|
12
|
+
# even when both httpx packages are installed in a legacy MCP environment.
|
|
13
|
+
from ksadk._mcp_compat import httpx_module
|
|
14
|
+
|
|
15
|
+
httpx = httpx_module()
|
|
16
|
+
|
|
17
|
+
from .protocol import LOCAL_ERROR_CODES, TunnelError, TunnelLimits, decode_request_body, encode
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(eq=False)
|
|
21
|
+
class ConnectorConnection:
|
|
22
|
+
agent_id: str
|
|
23
|
+
services: dict[str, dict]
|
|
24
|
+
websocket: Any = field(repr=False)
|
|
25
|
+
limits: TunnelLimits
|
|
26
|
+
connector_id: str = field(default_factory=lambda: uuid.uuid4().hex)
|
|
27
|
+
pending: dict[str, asyncio.Queue] = field(default_factory=dict, repr=False)
|
|
28
|
+
_send_lock: asyncio.Lock = field(default_factory=asyncio.Lock, repr=False)
|
|
29
|
+
operations: set[asyncio.Timeout] = field(default_factory=set, repr=False)
|
|
30
|
+
closed: bool = False
|
|
31
|
+
owner: dict | None = None
|
|
32
|
+
|
|
33
|
+
async def send(self, frame: dict) -> None:
|
|
34
|
+
raw = encode(frame, self.limits)
|
|
35
|
+
async with asyncio.timeout(self.limits.send_timeout):
|
|
36
|
+
async with self._send_lock:
|
|
37
|
+
await self.websocket.send_text(raw)
|
|
38
|
+
|
|
39
|
+
async def forward(self, service: str, request: httpx.Request) -> httpx.Response:
|
|
40
|
+
body = decode_request_body(await request.aread())
|
|
41
|
+
if self.closed:
|
|
42
|
+
raise TunnelError("disconnected")
|
|
43
|
+
if len(self.pending) >= 3 * self.limits.max_inflight:
|
|
44
|
+
raise TunnelError("busy")
|
|
45
|
+
request_id = uuid.uuid4().hex
|
|
46
|
+
queue = asyncio.Queue(maxsize=32)
|
|
47
|
+
self.pending[request_id] = queue
|
|
48
|
+
stream = ResponseStream(self, request_id, queue)
|
|
49
|
+
try:
|
|
50
|
+
await self.send(
|
|
51
|
+
{
|
|
52
|
+
"type": "http_request",
|
|
53
|
+
"id": request_id,
|
|
54
|
+
"server": service,
|
|
55
|
+
"method": request.method,
|
|
56
|
+
"path": request.url.path.strip("/"),
|
|
57
|
+
"query": request.url.query.decode("ascii"),
|
|
58
|
+
"headers": {
|
|
59
|
+
k: v
|
|
60
|
+
for k, v in request.headers.items()
|
|
61
|
+
if k.lower() not in {"host", "content-length", "accept-encoding"}
|
|
62
|
+
},
|
|
63
|
+
"body": body,
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
head = await stream.receive()
|
|
67
|
+
if head["type"] != "http_response":
|
|
68
|
+
raise TunnelError("invalid_result")
|
|
69
|
+
return httpx.Response(head["status"], headers=head["headers"], stream=stream)
|
|
70
|
+
except BaseException:
|
|
71
|
+
await stream.aclose()
|
|
72
|
+
raise
|
|
73
|
+
|
|
74
|
+
def dispatch(self, frame: dict) -> None:
|
|
75
|
+
if frame.get("type") not in {"http_response", "http_chunk", "http_end", "http_error"}:
|
|
76
|
+
raise ValueError("unexpected HTTP tunnel frame")
|
|
77
|
+
frame_type = frame["type"]
|
|
78
|
+
if frame_type == "http_response":
|
|
79
|
+
status, headers = frame.get("status"), frame.get("headers")
|
|
80
|
+
if type(status) is not int or not 100 <= status <= 599 or not isinstance(headers, dict):
|
|
81
|
+
raise ValueError("invalid HTTP response head")
|
|
82
|
+
if any(not isinstance(k, str) or not isinstance(v, str) for k, v in headers.items()):
|
|
83
|
+
raise ValueError("invalid HTTP response headers")
|
|
84
|
+
elif frame_type == "http_chunk" and not isinstance(frame.get("data"), str):
|
|
85
|
+
raise ValueError("invalid HTTP response chunk")
|
|
86
|
+
queue = self.pending.get(frame["id"])
|
|
87
|
+
if queue is not None:
|
|
88
|
+
if queue.full():
|
|
89
|
+
# Never let one slow response block the shared WS reader.
|
|
90
|
+
self.pending.pop(frame["id"])
|
|
91
|
+
queue.get_nowait()
|
|
92
|
+
queue.put_nowait({"type": "http_error"})
|
|
93
|
+
else:
|
|
94
|
+
queue.put_nowait(frame)
|
|
95
|
+
|
|
96
|
+
def fail_all(self) -> None:
|
|
97
|
+
self.closed = True
|
|
98
|
+
# Wake MCP sessions too, including a caller waiting on a parsed SSE event.
|
|
99
|
+
for deadline in self.operations:
|
|
100
|
+
if not deadline.expired():
|
|
101
|
+
deadline.reschedule(asyncio.get_running_loop().time())
|
|
102
|
+
for queue in self.pending.values():
|
|
103
|
+
if queue.full():
|
|
104
|
+
queue.get_nowait()
|
|
105
|
+
queue.put_nowait({"type": "http_error"})
|
|
106
|
+
self.pending.clear()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class ResponseStream(httpx.AsyncByteStream):
|
|
110
|
+
def __init__(self, connection, request_id, queue):
|
|
111
|
+
self.connection = connection
|
|
112
|
+
self.request_id = request_id
|
|
113
|
+
self.queue = queue
|
|
114
|
+
self.done = False
|
|
115
|
+
|
|
116
|
+
async def receive(self):
|
|
117
|
+
async with asyncio.timeout(self.connection.limits.request_timeout):
|
|
118
|
+
frame = await self.queue.get()
|
|
119
|
+
if frame["type"] == "http_error":
|
|
120
|
+
code = frame.get("error")
|
|
121
|
+
raise TunnelError(
|
|
122
|
+
code
|
|
123
|
+
if isinstance(code, str) and code in LOCAL_ERROR_CODES
|
|
124
|
+
else "local_service_error"
|
|
125
|
+
)
|
|
126
|
+
return frame
|
|
127
|
+
|
|
128
|
+
async def __aiter__(self):
|
|
129
|
+
received = 0
|
|
130
|
+
try:
|
|
131
|
+
while True:
|
|
132
|
+
frame = await self.receive()
|
|
133
|
+
if frame["type"] == "http_end":
|
|
134
|
+
self.done = True
|
|
135
|
+
return
|
|
136
|
+
if frame["type"] != "http_chunk":
|
|
137
|
+
raise TunnelError("invalid_result")
|
|
138
|
+
data = frame["data"].encode("utf-8")
|
|
139
|
+
received += len(data)
|
|
140
|
+
if received > self.connection.limits.max_response_bytes:
|
|
141
|
+
raise TunnelError("frame_too_large")
|
|
142
|
+
yield data
|
|
143
|
+
finally:
|
|
144
|
+
await self.aclose()
|
|
145
|
+
|
|
146
|
+
async def aclose(self):
|
|
147
|
+
if self.queue is None:
|
|
148
|
+
return
|
|
149
|
+
self.queue = None
|
|
150
|
+
self.connection.pending.pop(self.request_id, None)
|
|
151
|
+
if not self.done and not self.connection.closed:
|
|
152
|
+
try:
|
|
153
|
+
await self.connection.send({"type": "http_cancel", "id": self.request_id})
|
|
154
|
+
except Exception:
|
|
155
|
+
pass
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class TunnelRegistry:
|
|
159
|
+
"""One registry per runtime app; duplicates never replace a live connector."""
|
|
160
|
+
|
|
161
|
+
def __init__(self):
|
|
162
|
+
self._connections: dict[tuple[str, str], ConnectorConnection] = {}
|
|
163
|
+
self._closed = False
|
|
164
|
+
self.peers = None
|
|
165
|
+
|
|
166
|
+
def add(self, connection: ConnectorConnection) -> None:
|
|
167
|
+
if self._closed:
|
|
168
|
+
raise TunnelError("closed")
|
|
169
|
+
if any(
|
|
170
|
+
(connection.agent_id, service) in self._connections for service in connection.services
|
|
171
|
+
):
|
|
172
|
+
raise TunnelError("duplicate_service")
|
|
173
|
+
for service in connection.services:
|
|
174
|
+
self._connections[connection.agent_id, service] = connection
|
|
175
|
+
if self.peers is not None:
|
|
176
|
+
connection.owner = self.peers.owner
|
|
177
|
+
|
|
178
|
+
def remove(self, connection: ConnectorConnection) -> None:
|
|
179
|
+
connection.fail_all()
|
|
180
|
+
for service in connection.services:
|
|
181
|
+
key = (connection.agent_id, service)
|
|
182
|
+
if self._connections.get(key) is connection:
|
|
183
|
+
self._connections.pop(key)
|
|
184
|
+
|
|
185
|
+
def connections(self, agent_id: str) -> list[tuple[str, ConnectorConnection]]:
|
|
186
|
+
return [
|
|
187
|
+
(service, conn)
|
|
188
|
+
for (agent, service), conn in self._connections.items()
|
|
189
|
+
if agent == agent_id and not conn.closed
|
|
190
|
+
]
|
|
191
|
+
|
|
192
|
+
async def discover_connections(self, agent_id):
|
|
193
|
+
if self.peers is None or not await self.peers.start():
|
|
194
|
+
return self.connections(agent_id)
|
|
195
|
+
local = self.connections(agent_id)
|
|
196
|
+
for _, connection in local:
|
|
197
|
+
connection.owner = self.peers.owner
|
|
198
|
+
connections = [*local, *await self.peers.discover(agent_id, has_local=bool(local))]
|
|
199
|
+
aliases = {}
|
|
200
|
+
for service, connection in connections:
|
|
201
|
+
identity = (connection.connector_id, json_owner(connection.owner))
|
|
202
|
+
if service in aliases and aliases[service] != identity:
|
|
203
|
+
raise TunnelError("ambiguous_service")
|
|
204
|
+
aliases[service] = identity
|
|
205
|
+
return connections
|
|
206
|
+
|
|
207
|
+
async def list_tools(self, agent_id, service, *, connector_id=None, owner=None):
|
|
208
|
+
return await self._operate(agent_id, service, connector_id, None, None, owner)
|
|
209
|
+
|
|
210
|
+
async def call_tool(self, agent_id, service, name, arguments, *, connector_id=None, owner=None):
|
|
211
|
+
if not isinstance(name, str) or not name or not isinstance(arguments, dict):
|
|
212
|
+
raise TunnelError("invalid_request")
|
|
213
|
+
return await self._operate(agent_id, service, connector_id, name, arguments, owner)
|
|
214
|
+
|
|
215
|
+
async def _operate(self, agent_id, service, connector_id, name, arguments, owner=None):
|
|
216
|
+
from .http_tools import TunnelTransport, api_operation, mcp_operation
|
|
217
|
+
|
|
218
|
+
conn = self._connections.get((agent_id, service))
|
|
219
|
+
if self.peers is not None:
|
|
220
|
+
if owner is not None and owner != self.peers.owner:
|
|
221
|
+
conn = await self.peers.resolve(agent_id, service, connector_id, owner)
|
|
222
|
+
if conn.owner != owner:
|
|
223
|
+
raise TunnelError("disconnected")
|
|
224
|
+
elif owner is None and (
|
|
225
|
+
conn is None or (connector_id is not None and conn.connector_id != connector_id)
|
|
226
|
+
):
|
|
227
|
+
connections = await self.discover_connections(agent_id)
|
|
228
|
+
conn = next(
|
|
229
|
+
(
|
|
230
|
+
candidate
|
|
231
|
+
for alias, candidate in connections
|
|
232
|
+
if alias == service
|
|
233
|
+
and (connector_id is None or candidate.connector_id == connector_id)
|
|
234
|
+
),
|
|
235
|
+
None,
|
|
236
|
+
)
|
|
237
|
+
if conn is None or (connector_id is not None and connector_id != conn.connector_id):
|
|
238
|
+
raise TunnelError("disconnected")
|
|
239
|
+
if len(conn.operations) >= conn.limits.max_inflight:
|
|
240
|
+
raise TunnelError("busy")
|
|
241
|
+
deadline = asyncio.timeout(conn.limits.request_timeout)
|
|
242
|
+
peer_operation = None
|
|
243
|
+
try:
|
|
244
|
+
descriptor = conn.services[service]
|
|
245
|
+
operation = mcp_operation if descriptor["protocol"] == "mcp" else api_operation
|
|
246
|
+
async with deadline:
|
|
247
|
+
conn.operations.add(deadline)
|
|
248
|
+
scope = (
|
|
249
|
+
self.peers.operation_scope(deadline)
|
|
250
|
+
if self.peers is not None
|
|
251
|
+
else nullcontext(None)
|
|
252
|
+
)
|
|
253
|
+
with scope as peer_operation:
|
|
254
|
+
return await operation(
|
|
255
|
+
TunnelTransport(conn, service), descriptor, name, arguments
|
|
256
|
+
)
|
|
257
|
+
except TunnelError as exc:
|
|
258
|
+
if exc.code in {
|
|
259
|
+
"local_mcp_error",
|
|
260
|
+
"local_service_error",
|
|
261
|
+
"timeout",
|
|
262
|
+
"disconnected",
|
|
263
|
+
"frame_too_large",
|
|
264
|
+
}:
|
|
265
|
+
raise TunnelError(exc.code, indeterminate=name is not None) from None
|
|
266
|
+
raise
|
|
267
|
+
except TimeoutError:
|
|
268
|
+
code = (
|
|
269
|
+
peer_operation.error
|
|
270
|
+
if peer_operation is not None and peer_operation.error
|
|
271
|
+
else "disconnected" if conn.closed else "timeout"
|
|
272
|
+
)
|
|
273
|
+
raise TunnelError(
|
|
274
|
+
code,
|
|
275
|
+
indeterminate=name is not None
|
|
276
|
+
and code not in {"busy", "forbidden", "invalid_request"},
|
|
277
|
+
) from None
|
|
278
|
+
except Exception:
|
|
279
|
+
code = (
|
|
280
|
+
peer_operation.error
|
|
281
|
+
if peer_operation is not None and peer_operation.error
|
|
282
|
+
else "local_service_error"
|
|
283
|
+
)
|
|
284
|
+
raise TunnelError(
|
|
285
|
+
code,
|
|
286
|
+
indeterminate=name is not None
|
|
287
|
+
and code not in {"busy", "forbidden", "invalid_request"},
|
|
288
|
+
) from None
|
|
289
|
+
finally:
|
|
290
|
+
conn.operations.discard(deadline)
|
|
291
|
+
|
|
292
|
+
async def close(self) -> None:
|
|
293
|
+
self._closed = True
|
|
294
|
+
connections = set(self._connections.values())
|
|
295
|
+
self._connections.clear()
|
|
296
|
+
if self.peers is not None:
|
|
297
|
+
await self.peers.close()
|
|
298
|
+
for conn in connections:
|
|
299
|
+
conn.fail_all()
|
|
300
|
+
await asyncio.gather(
|
|
301
|
+
*(conn.websocket.close(code=1001) for conn in connections), return_exceptions=True
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def json_owner(owner):
|
|
306
|
+
return (owner["address"], owner["instance_id"]) if owner is not None else None
|
ksadk/tunnel/runtime.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""Deployment-owned tunnel configuration and app/runner binding."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from .registry import TunnelRegistry
|
|
10
|
+
from .server import TunnelAgentPolicy
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class TunnelBinding:
|
|
15
|
+
policy: TunnelAgentPolicy
|
|
16
|
+
registry: TunnelRegistry
|
|
17
|
+
|
|
18
|
+
async def start(self):
|
|
19
|
+
if self.registry.peers is not None:
|
|
20
|
+
await self.registry.peers.start()
|
|
21
|
+
|
|
22
|
+
async def close(self):
|
|
23
|
+
await self.registry.close()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class DeferredTunnel:
|
|
27
|
+
"""Resolve the exported declaration on normal runner load or the first connector request."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, launch):
|
|
30
|
+
from threading import Lock
|
|
31
|
+
|
|
32
|
+
self.launch = launch
|
|
33
|
+
self.binding = None
|
|
34
|
+
self.resolved = False
|
|
35
|
+
self._lock = Lock()
|
|
36
|
+
self.peers = None
|
|
37
|
+
|
|
38
|
+
def _peer_registry(self):
|
|
39
|
+
# Peer requests use only the resolved registry; they never import agents.
|
|
40
|
+
return self.binding.registry if self.binding is not None else None
|
|
41
|
+
|
|
42
|
+
async def start(self):
|
|
43
|
+
if self.peers is not None:
|
|
44
|
+
await self.peers.start()
|
|
45
|
+
|
|
46
|
+
def resolve(self, root, module):
|
|
47
|
+
from ksadk.agent import TunnelDeclaration
|
|
48
|
+
|
|
49
|
+
with self._lock:
|
|
50
|
+
if not self.resolved:
|
|
51
|
+
declaration = getattr(root, "_ksadk_tunnel_declaration", None)
|
|
52
|
+
if isinstance(declaration, TunnelDeclaration) and declaration.enabled:
|
|
53
|
+
entry = self.launch.detection.entry_point
|
|
54
|
+
if (
|
|
55
|
+
Path(module.__file__).resolve()
|
|
56
|
+
!= (self.launch.project_dir / entry).resolve()
|
|
57
|
+
):
|
|
58
|
+
raise ValueError("Tunnel declaration loaded from a different project")
|
|
59
|
+
token = os.environ.get(declaration.token_env, "")
|
|
60
|
+
if not token.strip():
|
|
61
|
+
raise ValueError(
|
|
62
|
+
f"Missing tunnel token in environment variable {declaration.token_env}"
|
|
63
|
+
)
|
|
64
|
+
peers = _peer_network(self._peer_registry, token=token)
|
|
65
|
+
self.binding = TunnelBinding(
|
|
66
|
+
TunnelAgentPolicy("root", token, services=None), TunnelRegistry()
|
|
67
|
+
)
|
|
68
|
+
self.peers = peers
|
|
69
|
+
self.binding.registry.peers = self.peers
|
|
70
|
+
self.resolved = True
|
|
71
|
+
return self.binding
|
|
72
|
+
|
|
73
|
+
def for_connector(self):
|
|
74
|
+
if not self.resolved:
|
|
75
|
+
from ksadk.runners.utils import load_agent_module
|
|
76
|
+
|
|
77
|
+
detection = self.launch.detection
|
|
78
|
+
root, module = load_agent_module(
|
|
79
|
+
str(self.launch.project_dir), detection.entry_point, detection.agent_variable
|
|
80
|
+
)
|
|
81
|
+
return self.resolve(root, module)
|
|
82
|
+
return self.binding
|
|
83
|
+
|
|
84
|
+
async def close(self):
|
|
85
|
+
if self.binding is not None:
|
|
86
|
+
await self.binding.registry.close()
|
|
87
|
+
elif self.peers is not None:
|
|
88
|
+
await self.peers.close()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def bind_runner(runner, binding: TunnelBinding) -> None:
|
|
92
|
+
"""Bind before lazy runner initialization; reject cross-app registry reuse."""
|
|
93
|
+
if isinstance(binding, DeferredTunnel):
|
|
94
|
+
runner._deferred_tunnel = binding
|
|
95
|
+
return
|
|
96
|
+
current = getattr(runner, "_tunnel_binding", None)
|
|
97
|
+
if current is not None and current != binding:
|
|
98
|
+
raise ValueError("runner already belongs to another tunnel binding")
|
|
99
|
+
if current is None and getattr(runner, "_agent", None) is not None:
|
|
100
|
+
raise ValueError("MCP tunnel must be configured before runner initialization")
|
|
101
|
+
runner._tunnel_binding = binding
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def configure_app_tunnel(config):
|
|
105
|
+
"""Prepare per-app tunnel state without importing the agent."""
|
|
106
|
+
launch = config.launch_context
|
|
107
|
+
tunnel_binding = launch.services.tunnel_binding if launch else None
|
|
108
|
+
if (
|
|
109
|
+
launch
|
|
110
|
+
and launch.runtime_type in {"adk", "langgraph"}
|
|
111
|
+
and getattr(launch.detection, "entry_point", None)
|
|
112
|
+
and getattr(launch.detection, "agent_variable", None)
|
|
113
|
+
and tunnel_binding is None
|
|
114
|
+
):
|
|
115
|
+
tunnel_binding = DeferredTunnel(launch)
|
|
116
|
+
if tunnel_binding is not None:
|
|
117
|
+
from dataclasses import replace
|
|
118
|
+
|
|
119
|
+
if launch.runtime_type not in {"adk", "langgraph"}:
|
|
120
|
+
raise ValueError("Tool tunnel requires an ADK or LangGraph RuntimeLaunchContext")
|
|
121
|
+
# Keep the caller's reusable config/context untouched: every app gets
|
|
122
|
+
# its own registry unless an explicit process-owned binding is supplied.
|
|
123
|
+
from copy import copy
|
|
124
|
+
|
|
125
|
+
config = copy(config)
|
|
126
|
+
if not isinstance(tunnel_binding, DeferredTunnel) and tunnel_binding.registry.peers is None:
|
|
127
|
+
tunnel_binding.registry.peers = _peer_network(
|
|
128
|
+
lambda: tunnel_binding.registry, token=tunnel_binding.policy.token
|
|
129
|
+
)
|
|
130
|
+
config.launch_context = replace(
|
|
131
|
+
launch, services=replace(launch.services, tunnel_binding=tunnel_binding)
|
|
132
|
+
)
|
|
133
|
+
if config.a2a_runtime_adapter is not None:
|
|
134
|
+
configure_tunnel = getattr(config.a2a_runtime_adapter, "configure_tunnel", None)
|
|
135
|
+
if callable(configure_tunnel):
|
|
136
|
+
configure_tunnel(tunnel_binding)
|
|
137
|
+
elif not isinstance(tunnel_binding, DeferredTunnel):
|
|
138
|
+
raise ValueError("A2A adapter must support the app's tool tunnel binding")
|
|
139
|
+
|
|
140
|
+
return config, tunnel_binding
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _peer_network(registry_provider, *, token):
|
|
144
|
+
from .peers import PeerConfig, PeerNetwork
|
|
145
|
+
|
|
146
|
+
config = PeerConfig.from_env(tunnel_token=token)
|
|
147
|
+
return PeerNetwork(config, registry_provider) if config is not None else None
|