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,246 @@
|
|
|
1
|
+
"""Static validation for Agent drafts and release contracts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Literal
|
|
7
|
+
from urllib.parse import urlparse
|
|
8
|
+
|
|
9
|
+
from jsonschema import Draft202012Validator # type: ignore[import-untyped]
|
|
10
|
+
from jsonschema.exceptions import SchemaError # type: ignore[import-untyped]
|
|
11
|
+
|
|
12
|
+
from ksadk.studio.capabilities import require_exact_version
|
|
13
|
+
from ksadk.studio.contracts import (
|
|
14
|
+
AgentDraft,
|
|
15
|
+
Diagnostic,
|
|
16
|
+
DiagnosticSeverity,
|
|
17
|
+
ValidationResult,
|
|
18
|
+
)
|
|
19
|
+
from ksadk.studio.errors import StudioError
|
|
20
|
+
|
|
21
|
+
_SECRET_REF = re.compile(r"^(env|keychain|secret-manager)://[A-Za-z0-9_.:/-]+$")
|
|
22
|
+
_SUSPECT_SECRET = re.compile(r"^(sk-|AKLT|ASIA)[A-Za-z0-9_-]{8,}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AgentValidator:
|
|
26
|
+
def validate(
|
|
27
|
+
self,
|
|
28
|
+
draft: AgentDraft,
|
|
29
|
+
*,
|
|
30
|
+
level: Literal["schema", "build", "release"] = "build",
|
|
31
|
+
raise_on_error: bool = False,
|
|
32
|
+
) -> ValidationResult:
|
|
33
|
+
diagnostics: list[Diagnostic] = []
|
|
34
|
+
spec = draft.spec
|
|
35
|
+
if not spec.instructions.system.strip():
|
|
36
|
+
diagnostics.append(
|
|
37
|
+
self._error(
|
|
38
|
+
"AGENT_SYSTEM_INSTRUCTION_REQUIRED",
|
|
39
|
+
"必须配置 system 指令",
|
|
40
|
+
"spec.instructions.system",
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
if spec.model is None and not spec.bindings.model_profile_id:
|
|
44
|
+
diagnostics.append(
|
|
45
|
+
self._error("AGENT_MODEL_REQUIRED", "必须配置模型", "spec.model")
|
|
46
|
+
)
|
|
47
|
+
elif spec.model is not None:
|
|
48
|
+
self._validate_model(draft, diagnostics)
|
|
49
|
+
self._validate_capabilities(draft, diagnostics)
|
|
50
|
+
if level == "release" and not spec.evaluation.suite_refs:
|
|
51
|
+
diagnostics.append(
|
|
52
|
+
self._error(
|
|
53
|
+
"EVALUATION_SUITE_REQUIRED",
|
|
54
|
+
"Release 校验要求至少一个评测集",
|
|
55
|
+
"spec.evaluation.suiteRefs",
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
valid = not any(item.severity == DiagnosticSeverity.ERROR for item in diagnostics)
|
|
59
|
+
result = ValidationResult(valid=valid, level=level, diagnostics=diagnostics)
|
|
60
|
+
if raise_on_error and not valid:
|
|
61
|
+
first = next(item for item in diagnostics if item.severity == DiagnosticSeverity.ERROR)
|
|
62
|
+
raise StudioError(
|
|
63
|
+
first.code,
|
|
64
|
+
first.message,
|
|
65
|
+
status_code=422,
|
|
66
|
+
field=first.field,
|
|
67
|
+
details={
|
|
68
|
+
"diagnostics": [
|
|
69
|
+
item.model_dump(by_alias=True, exclude_none=True, mode="json")
|
|
70
|
+
for item in diagnostics
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
)
|
|
74
|
+
return result
|
|
75
|
+
|
|
76
|
+
def _validate_model(
|
|
77
|
+
self,
|
|
78
|
+
draft: AgentDraft,
|
|
79
|
+
diagnostics: list[Diagnostic],
|
|
80
|
+
) -> None:
|
|
81
|
+
model = draft.spec.model
|
|
82
|
+
assert model is not None
|
|
83
|
+
endpoint = model.endpoint_url or model.base_url or ""
|
|
84
|
+
parsed = urlparse(endpoint)
|
|
85
|
+
if parsed.scheme not in {"http", "https"} or not parsed.hostname:
|
|
86
|
+
diagnostics.append(
|
|
87
|
+
self._error(
|
|
88
|
+
"MODEL_ENDPOINT_INVALID",
|
|
89
|
+
"模型地址必须是有效的 HTTP(S) URL",
|
|
90
|
+
"spec.model.endpointUrl",
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
credential = model.credential_ref.strip()
|
|
94
|
+
if _SUSPECT_SECRET.match(credential) or not _SECRET_REF.fullmatch(credential):
|
|
95
|
+
diagnostics.append(
|
|
96
|
+
self._error(
|
|
97
|
+
"SECRET_REFERENCE_INVALID",
|
|
98
|
+
"credentialRef 必须使用 env://、keychain:// 或 secret-manager:// 引用",
|
|
99
|
+
"spec.model.credentialRef",
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
network = draft.spec.security.network
|
|
103
|
+
if network.mode == "restricted" and parsed.hostname:
|
|
104
|
+
allowed = {host.lower().rstrip(".") for host in network.allowed_hosts}
|
|
105
|
+
if parsed.hostname.lower().rstrip(".") not in allowed:
|
|
106
|
+
diagnostics.append(
|
|
107
|
+
self._error(
|
|
108
|
+
"NETWORK_TARGET_DENIED",
|
|
109
|
+
"模型 hostname 不在 security.network.allowedHosts 中",
|
|
110
|
+
"spec.security.network.allowedHosts",
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def _validate_capabilities(
|
|
115
|
+
self,
|
|
116
|
+
draft: AgentDraft,
|
|
117
|
+
diagnostics: list[Diagnostic],
|
|
118
|
+
) -> None:
|
|
119
|
+
capabilities = draft.spec.capabilities
|
|
120
|
+
names: set[str] = set()
|
|
121
|
+
for kind, refs in (
|
|
122
|
+
("skills", capabilities.skills),
|
|
123
|
+
("mcpServers", capabilities.mcp_servers),
|
|
124
|
+
):
|
|
125
|
+
for index, ref in enumerate(refs):
|
|
126
|
+
try:
|
|
127
|
+
require_exact_version(
|
|
128
|
+
ref.version,
|
|
129
|
+
field=f"spec.capabilities.{kind}[{index}].version",
|
|
130
|
+
)
|
|
131
|
+
except StudioError as exc:
|
|
132
|
+
diagnostics.append(self._error(exc.code, exc.message, exc.field))
|
|
133
|
+
key = f"{kind}:{ref.name}"
|
|
134
|
+
if key in names:
|
|
135
|
+
diagnostics.append(
|
|
136
|
+
self._error(
|
|
137
|
+
"CAPABILITY_DUPLICATE",
|
|
138
|
+
"能力名称重复",
|
|
139
|
+
f"spec.capabilities.{kind}[{index}].name",
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
names.add(key)
|
|
143
|
+
env_refs = getattr(ref, "env_refs", {})
|
|
144
|
+
for env_name, secret_ref in env_refs.items():
|
|
145
|
+
if not _SECRET_REF.fullmatch(secret_ref):
|
|
146
|
+
diagnostics.append(
|
|
147
|
+
self._error(
|
|
148
|
+
"SECRET_REFERENCE_INVALID",
|
|
149
|
+
f"MCP 环境变量 {env_name} 必须使用 Secret 引用",
|
|
150
|
+
f"spec.capabilities.{kind}[{index}].envRefs.{env_name}",
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
allowed_permissions = set(draft.spec.security.allowed_permissions)
|
|
155
|
+
mcp_names = {ref.name for ref in capabilities.mcp_servers if ref.enabled}
|
|
156
|
+
tool_names: set[str] = set()
|
|
157
|
+
for index, tool in enumerate(capabilities.tools):
|
|
158
|
+
try:
|
|
159
|
+
require_exact_version(
|
|
160
|
+
tool.version,
|
|
161
|
+
field=f"spec.capabilities.tools[{index}].version",
|
|
162
|
+
)
|
|
163
|
+
except StudioError as exc:
|
|
164
|
+
diagnostics.append(self._error(exc.code, exc.message, exc.field))
|
|
165
|
+
if tool.name in tool_names:
|
|
166
|
+
diagnostics.append(
|
|
167
|
+
self._error(
|
|
168
|
+
"CAPABILITY_DUPLICATE",
|
|
169
|
+
"Tool 名称重复",
|
|
170
|
+
f"spec.capabilities.tools[{index}].name",
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
tool_names.add(tool.name)
|
|
174
|
+
for schema_name, schema in (
|
|
175
|
+
("inputSchema", tool.input_schema),
|
|
176
|
+
("outputSchema", tool.output_schema),
|
|
177
|
+
):
|
|
178
|
+
try:
|
|
179
|
+
Draft202012Validator.check_schema(schema)
|
|
180
|
+
except SchemaError as exc:
|
|
181
|
+
diagnostics.append(
|
|
182
|
+
self._error(
|
|
183
|
+
"TOOL_SCHEMA_INVALID",
|
|
184
|
+
f"Tool {schema_name} 不是合法 JSON Schema: {exc.message}",
|
|
185
|
+
f"spec.capabilities.tools[{index}].{schema_name}",
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
missing = sorted(set(tool.permissions) - allowed_permissions)
|
|
189
|
+
if missing:
|
|
190
|
+
diagnostics.append(
|
|
191
|
+
self._error(
|
|
192
|
+
"TOOL_PERMISSION_DENIED",
|
|
193
|
+
"Tool 请求了 Agent 未允许的权限",
|
|
194
|
+
f"spec.capabilities.tools[{index}].permissions",
|
|
195
|
+
hint=f"缺少权限: {', '.join(missing)}",
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
if tool.side_effect in {"write", "external"} and tool.approval == "never":
|
|
199
|
+
diagnostics.append(
|
|
200
|
+
self._warning(
|
|
201
|
+
"TOOL_AUTO_APPROVAL_RISK",
|
|
202
|
+
"有写入或外部副作用的 Tool 已配置为自动允许",
|
|
203
|
+
f"spec.capabilities.tools[{index}].approval",
|
|
204
|
+
hint="仅建议在受信任工作区使用宽松策略",
|
|
205
|
+
)
|
|
206
|
+
)
|
|
207
|
+
if tool.executor == "mcp" and tool.mcp_server not in mcp_names:
|
|
208
|
+
diagnostics.append(
|
|
209
|
+
self._error(
|
|
210
|
+
"CAPABILITY_UNRESOLVED",
|
|
211
|
+
"MCP Tool 引用了未启用的 MCP Server",
|
|
212
|
+
f"spec.capabilities.tools[{index}].mcpServer",
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
@staticmethod
|
|
217
|
+
def _error(
|
|
218
|
+
code: str,
|
|
219
|
+
message: str,
|
|
220
|
+
field: str | None,
|
|
221
|
+
*,
|
|
222
|
+
hint: str | None = None,
|
|
223
|
+
) -> Diagnostic:
|
|
224
|
+
return Diagnostic(
|
|
225
|
+
severity=DiagnosticSeverity.ERROR,
|
|
226
|
+
code=code,
|
|
227
|
+
message=message,
|
|
228
|
+
field=field,
|
|
229
|
+
hint=hint,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
@staticmethod
|
|
233
|
+
def _warning(
|
|
234
|
+
code: str,
|
|
235
|
+
message: str,
|
|
236
|
+
field: str | None,
|
|
237
|
+
*,
|
|
238
|
+
hint: str | None = None,
|
|
239
|
+
) -> Diagnostic:
|
|
240
|
+
return Diagnostic(
|
|
241
|
+
severity=DiagnosticSeverity.WARNING,
|
|
242
|
+
code=code,
|
|
243
|
+
message=message,
|
|
244
|
+
field=field,
|
|
245
|
+
hint=hint,
|
|
246
|
+
)
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""Workspace initialization and path-safe file operations."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import tempfile
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import yaml # type: ignore[import-untyped]
|
|
10
|
+
|
|
11
|
+
from ksadk.studio.errors import StudioError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Workspace:
|
|
15
|
+
def __init__(self, root: Path | str) -> None:
|
|
16
|
+
self.root = Path(root).expanduser().resolve()
|
|
17
|
+
|
|
18
|
+
def matches_configured_root_path(self, path: str) -> bool:
|
|
19
|
+
"""Return whether a no-op workspace-open request names this exact root.
|
|
20
|
+
|
|
21
|
+
The local Studio daemon is intentionally bound to one workspace for its
|
|
22
|
+
lifetime. Comparing the advertised canonical string avoids resolving
|
|
23
|
+
a client-supplied pathname in the workspace-open endpoint.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
return path == os.fspath(self.root)
|
|
27
|
+
|
|
28
|
+
def initialize(self) -> None:
|
|
29
|
+
self.root.mkdir(parents=True, exist_ok=True)
|
|
30
|
+
for relative in (
|
|
31
|
+
"agents",
|
|
32
|
+
"capabilities/skills",
|
|
33
|
+
"capabilities/tools",
|
|
34
|
+
"environments",
|
|
35
|
+
".agentkit/catalog/models",
|
|
36
|
+
".agentkit/catalog/mcp",
|
|
37
|
+
".agentkit/catalog/tools",
|
|
38
|
+
".agentkit/catalog/tool-sources",
|
|
39
|
+
".agentkit/codex-drafts",
|
|
40
|
+
".agentkit/builds",
|
|
41
|
+
".agentkit/operations",
|
|
42
|
+
".agentkit/runs",
|
|
43
|
+
".agentkit/traces",
|
|
44
|
+
".agentkit/assets/agent-avatars",
|
|
45
|
+
".agentkit/cache",
|
|
46
|
+
".agentkit/trash",
|
|
47
|
+
"dist",
|
|
48
|
+
):
|
|
49
|
+
(self.root / relative).mkdir(parents=True, exist_ok=True)
|
|
50
|
+
manifest = self.root / "agentkit.yaml"
|
|
51
|
+
if not manifest.exists():
|
|
52
|
+
self.atomic_write_yaml(
|
|
53
|
+
manifest,
|
|
54
|
+
{
|
|
55
|
+
"apiVersion": "agentkit.ksyun.com/v1alpha1",
|
|
56
|
+
"kind": "AgentWorkspace",
|
|
57
|
+
"metadata": {"name": self.root.name or "agentkit-workspace"},
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
gitignore = self.root / ".gitignore"
|
|
61
|
+
wanted = ".agentkit/secrets.env\n"
|
|
62
|
+
existing = gitignore.read_text(encoding="utf-8") if gitignore.exists() else ""
|
|
63
|
+
if ".agentkit/secrets.env" not in existing.splitlines():
|
|
64
|
+
gitignore.write_text(
|
|
65
|
+
(existing + ("\n" if existing and not existing.endswith("\n") else "") + wanted),
|
|
66
|
+
encoding="utf-8",
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def resolve(self, relative: Path | str, *, must_exist: bool = False) -> Path:
|
|
70
|
+
root_path = os.path.realpath(os.fspath(self.root))
|
|
71
|
+
raw_path = os.fspath(relative)
|
|
72
|
+
requested_path = (
|
|
73
|
+
raw_path if os.path.isabs(raw_path) else os.path.join(root_path, raw_path)
|
|
74
|
+
)
|
|
75
|
+
candidate_path = os.path.realpath(requested_path)
|
|
76
|
+
if candidate_path == root_path:
|
|
77
|
+
candidate = self.root
|
|
78
|
+
else:
|
|
79
|
+
root_prefix = root_path if root_path.endswith(os.sep) else f"{root_path}{os.sep}"
|
|
80
|
+
# `realpath` resolves traversal and symlinks before this segment-boundary check.
|
|
81
|
+
if candidate_path.startswith(root_prefix):
|
|
82
|
+
candidate = Path(candidate_path)
|
|
83
|
+
else:
|
|
84
|
+
raise StudioError(
|
|
85
|
+
"WORKSPACE_PATH_FORBIDDEN",
|
|
86
|
+
"路径不在当前工作区内",
|
|
87
|
+
status_code=403,
|
|
88
|
+
details={"path": str(relative)},
|
|
89
|
+
)
|
|
90
|
+
if must_exist:
|
|
91
|
+
candidate.stat()
|
|
92
|
+
return candidate
|
|
93
|
+
|
|
94
|
+
def relative(self, path: Path | str) -> str:
|
|
95
|
+
candidate = self.resolve(path)
|
|
96
|
+
return candidate.relative_to(self.root).as_posix()
|
|
97
|
+
|
|
98
|
+
def atomic_write_text(self, path: Path | str, content: str) -> None:
|
|
99
|
+
target = self.resolve(path)
|
|
100
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
101
|
+
descriptor, temporary_name = tempfile.mkstemp(
|
|
102
|
+
prefix=f".{target.name}.", suffix=".tmp", dir=target.parent
|
|
103
|
+
)
|
|
104
|
+
temporary = Path(temporary_name)
|
|
105
|
+
try:
|
|
106
|
+
with os.fdopen(descriptor, "w", encoding="utf-8", newline="\n") as stream:
|
|
107
|
+
stream.write(content)
|
|
108
|
+
stream.flush()
|
|
109
|
+
os.fsync(stream.fileno())
|
|
110
|
+
os.replace(temporary, target)
|
|
111
|
+
finally:
|
|
112
|
+
temporary.unlink(missing_ok=True)
|
|
113
|
+
|
|
114
|
+
def atomic_write_bytes(self, path: Path | str, content: bytes) -> None:
|
|
115
|
+
target = self.resolve(path)
|
|
116
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
117
|
+
descriptor, temporary_name = tempfile.mkstemp(
|
|
118
|
+
prefix=f".{target.name}.", suffix=".tmp", dir=target.parent
|
|
119
|
+
)
|
|
120
|
+
temporary = Path(temporary_name)
|
|
121
|
+
try:
|
|
122
|
+
with os.fdopen(descriptor, "wb") as stream:
|
|
123
|
+
stream.write(content)
|
|
124
|
+
stream.flush()
|
|
125
|
+
os.fsync(stream.fileno())
|
|
126
|
+
os.replace(temporary, target)
|
|
127
|
+
finally:
|
|
128
|
+
temporary.unlink(missing_ok=True)
|
|
129
|
+
|
|
130
|
+
def atomic_write_yaml(self, path: Path | str, payload: object) -> None:
|
|
131
|
+
content = yaml.safe_dump(
|
|
132
|
+
payload,
|
|
133
|
+
allow_unicode=True,
|
|
134
|
+
sort_keys=False,
|
|
135
|
+
default_flow_style=False,
|
|
136
|
+
)
|
|
137
|
+
self.atomic_write_text(path, content)
|
ksadk/terminal_exec_policy.py
CHANGED
|
@@ -140,10 +140,9 @@ def validate_terminal_exec_argv(
|
|
|
140
140
|
|
|
141
141
|
normalized = normalize_exec_argv(argv, policy_name=policy.name)
|
|
142
142
|
allowed_exact = tuple(tuple(item) for item in policy.default_exact)
|
|
143
|
-
allowed_prefixes = (
|
|
144
|
-
tuple(
|
|
145
|
-
|
|
146
|
-
)
|
|
143
|
+
allowed_prefixes = tuple(
|
|
144
|
+
tuple(item) for item in policy.default_prefixes
|
|
145
|
+
) + _env_allowlist_prefixes(policy.env_names, policy_name=policy.name)
|
|
147
146
|
|
|
148
147
|
if _matches_exact_or_prefix(
|
|
149
148
|
normalized,
|
ksadk/tools/gateway.py
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
import hashlib
|
|
5
4
|
import json
|
|
5
|
+
import os
|
|
6
6
|
import shlex
|
|
7
7
|
from collections.abc import Callable, Mapping, Sequence
|
|
8
8
|
from dataclasses import dataclass, field
|
|
9
9
|
from typing import Any
|
|
10
10
|
from uuid import uuid4
|
|
11
11
|
|
|
12
|
+
from ksadk.runtime_context import get_current_invocation_context
|
|
13
|
+
|
|
12
14
|
|
|
13
15
|
@dataclass(frozen=True)
|
|
14
16
|
class ToolPolicy:
|
|
15
17
|
risk_level: str = "low"
|
|
16
18
|
side_effects: Sequence[str] = field(default_factory=tuple)
|
|
19
|
+
# Approval scopes classify operations which might need an interactive
|
|
20
|
+
# decision. ``public_network`` is intentionally a read-only exception:
|
|
21
|
+
# web discovery must remain available in every approval profile.
|
|
22
|
+
approval_scopes: Sequence[str] = field(default_factory=tuple)
|
|
23
|
+
# Use only for tools whose operation is inherently safe to run without a
|
|
24
|
+
# human decision. This wins over a risk level or explicit legacy policy.
|
|
25
|
+
approval_exempt: bool = False
|
|
17
26
|
requires_approval: bool | None = None
|
|
18
27
|
|
|
19
28
|
|
|
@@ -50,8 +59,9 @@ class ToolGateway:
|
|
|
50
59
|
|
|
51
60
|
@staticmethod
|
|
52
61
|
def _approval_mode() -> str:
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
context = get_current_invocation_context()
|
|
63
|
+
requested_mode = context.tool_approval_mode if context is not None else None
|
|
64
|
+
return normalize_tool_approval_mode(requested_mode)
|
|
55
65
|
|
|
56
66
|
@staticmethod
|
|
57
67
|
def _is_approved(approval: Mapping[str, Any] | None) -> bool:
|
|
@@ -108,24 +118,76 @@ def tool_policy_requires_approval(
|
|
|
108
118
|
*,
|
|
109
119
|
approval_mode: str | None = None,
|
|
110
120
|
) -> bool:
|
|
111
|
-
mode = (approval_mode
|
|
121
|
+
mode = normalize_tool_approval_mode(approval_mode)
|
|
122
|
+
if policy.approval_exempt or _is_read_only_public_network_policy(policy):
|
|
123
|
+
return False
|
|
112
124
|
if policy.requires_approval is not None:
|
|
113
|
-
return policy.requires_approval and mode != "
|
|
114
|
-
if mode
|
|
125
|
+
return policy.requires_approval and mode != "full"
|
|
126
|
+
if mode == "full":
|
|
115
127
|
return False
|
|
128
|
+
if mode == "ask" and policy.approval_scopes:
|
|
129
|
+
return True
|
|
116
130
|
return policy.risk_level.lower() in {"medium", "high", "critical"}
|
|
117
131
|
|
|
118
132
|
|
|
133
|
+
def _is_read_only_public_network_policy(policy: ToolPolicy) -> bool:
|
|
134
|
+
"""Keep public web reads available even under the most cautious profile.
|
|
135
|
+
|
|
136
|
+
A network write must declare a side effect, so it does not match this
|
|
137
|
+
exemption and can still require approval.
|
|
138
|
+
"""
|
|
139
|
+
return bool(policy.approval_scopes) and set(policy.approval_scopes) <= {
|
|
140
|
+
"public_network"
|
|
141
|
+
} and not policy.side_effects
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def normalize_tool_approval_mode(value: str | None = None) -> str:
|
|
145
|
+
"""Resolve the compact runtime approval profile.
|
|
146
|
+
|
|
147
|
+
``ask`` confirms risky and non-network scoped operations; ``risk``
|
|
148
|
+
confirms medium-and-higher risk only; ``full`` leaves default policies
|
|
149
|
+
unprompted. Public web reads remain approval-free in every profile. The
|
|
150
|
+
process environment remains a default for non-UI callers, while a
|
|
151
|
+
request-scoped mode wins for the duration of that invocation.
|
|
152
|
+
"""
|
|
153
|
+
raw = str(value or os.environ.get("KSADK_TOOL_APPROVAL_MODE", "risk")).strip().lower()
|
|
154
|
+
return raw if raw in {"ask", "risk", "full"} else "risk"
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def tool_approval_capability() -> dict[str, Any]:
|
|
158
|
+
"""Describe the single profile interface exposed to hosted UIs."""
|
|
159
|
+
return {
|
|
160
|
+
"Modes": ["ask", "risk", "full"],
|
|
161
|
+
"DefaultMode": normalize_tool_approval_mode(),
|
|
162
|
+
"RuntimeOverride": True,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
119
166
|
def check_command_policy(command: str) -> dict[str, Any]:
|
|
120
167
|
text = str(command or "").strip()
|
|
121
168
|
if not text:
|
|
122
|
-
return {
|
|
169
|
+
return {
|
|
170
|
+
"ok": False,
|
|
171
|
+
"decision": "reject",
|
|
172
|
+
"error_type": "command_required",
|
|
173
|
+
"error_message": "command is required",
|
|
174
|
+
}
|
|
123
175
|
try:
|
|
124
176
|
tokens = shlex.split(text)
|
|
125
177
|
except ValueError as exc:
|
|
126
|
-
return {
|
|
178
|
+
return {
|
|
179
|
+
"ok": False,
|
|
180
|
+
"decision": "reject",
|
|
181
|
+
"error_type": "invalid_command",
|
|
182
|
+
"error_message": str(exc),
|
|
183
|
+
}
|
|
127
184
|
if not tokens:
|
|
128
|
-
return {
|
|
185
|
+
return {
|
|
186
|
+
"ok": False,
|
|
187
|
+
"decision": "reject",
|
|
188
|
+
"error_type": "command_required",
|
|
189
|
+
"error_message": "command is required",
|
|
190
|
+
}
|
|
129
191
|
if _contains_recursive_rm(tokens):
|
|
130
192
|
return _command_rejected("recursive rm is not allowed without explicit approval")
|
|
131
193
|
if any(token in _DANGEROUS_COMMAND_TOKENS for token in tokens):
|
|
@@ -137,12 +199,19 @@ def check_command_policy(command: str) -> dict[str, Any]:
|
|
|
137
199
|
if subcommand in _DANGEROUS_GIT_COMMANDS:
|
|
138
200
|
return _command_rejected(f"git {subcommand} is not allowed without explicit approval")
|
|
139
201
|
if _references_metadata_endpoint(tokens):
|
|
140
|
-
return _command_rejected(
|
|
202
|
+
return _command_rejected(
|
|
203
|
+
"metadata/private endpoint access is not allowed by default policy"
|
|
204
|
+
)
|
|
141
205
|
return {"ok": True, "decision": "allow", "reason": "default_allow"}
|
|
142
206
|
|
|
143
207
|
|
|
144
208
|
def _command_rejected(message: str) -> dict[str, Any]:
|
|
145
|
-
return {
|
|
209
|
+
return {
|
|
210
|
+
"ok": False,
|
|
211
|
+
"decision": "reject",
|
|
212
|
+
"error_type": "command_rejected",
|
|
213
|
+
"error_message": message,
|
|
214
|
+
}
|
|
146
215
|
|
|
147
216
|
|
|
148
217
|
def _contains_recursive_rm(tokens: Sequence[str]) -> bool:
|
|
@@ -162,7 +231,9 @@ def _references_metadata_endpoint(tokens: Sequence[str]) -> bool:
|
|
|
162
231
|
|
|
163
232
|
def _canonical_tool_args(tool_args: Any) -> str:
|
|
164
233
|
try:
|
|
165
|
-
return json.dumps(
|
|
234
|
+
return json.dumps(
|
|
235
|
+
tool_args or {}, ensure_ascii=False, sort_keys=True, separators=(",", ":")
|
|
236
|
+
)
|
|
166
237
|
except TypeError:
|
|
167
238
|
return json.dumps(str(tool_args), ensure_ascii=False, separators=(",", ":"))
|
|
168
239
|
|
|
@@ -185,7 +256,9 @@ def build_tool_receipt_idempotency_key(
|
|
|
185
256
|
"tool_args": _canonical_tool_args(tool_args),
|
|
186
257
|
}
|
|
187
258
|
digest = hashlib.sha256(
|
|
188
|
-
json.dumps(payload, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode(
|
|
259
|
+
json.dumps(payload, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode(
|
|
260
|
+
"utf-8"
|
|
261
|
+
)
|
|
189
262
|
).hexdigest()
|
|
190
263
|
return f"tool_receipt:{digest}"
|
|
191
264
|
|
|
@@ -197,6 +270,15 @@ def approval_interrupt_info_from_result(
|
|
|
197
270
|
tool_args: Any = None,
|
|
198
271
|
run_id: str | None = None,
|
|
199
272
|
) -> dict[str, Any] | None:
|
|
273
|
+
# LangGraph exposes ToolMessage.content as text in callback and graph-update
|
|
274
|
+
# streams. Preserve the structured gateway contract when that text is a
|
|
275
|
+
# JSON object so an approval remains an interrupt instead of becoming a
|
|
276
|
+
# normal tool result followed by model-authored prose.
|
|
277
|
+
if isinstance(result, str):
|
|
278
|
+
try:
|
|
279
|
+
result = json.loads(result)
|
|
280
|
+
except (TypeError, ValueError):
|
|
281
|
+
return None
|
|
200
282
|
if not isinstance(result, Mapping):
|
|
201
283
|
return None
|
|
202
284
|
if str(result.get("type") or "") != "approval_required":
|
|
@@ -222,8 +304,12 @@ def approval_interrupt_info_from_result(
|
|
|
222
304
|
or {}
|
|
223
305
|
),
|
|
224
306
|
"risk_level": str(approval_request.get("risk_level") or result.get("risk_level") or ""),
|
|
225
|
-
"side_effects": list(
|
|
226
|
-
|
|
307
|
+
"side_effects": list(
|
|
308
|
+
approval_request.get("side_effects") or result.get("side_effects") or []
|
|
309
|
+
),
|
|
310
|
+
"server_label": str(
|
|
311
|
+
approval_request.get("server_label") or result.get("server_label") or "ksadk"
|
|
312
|
+
),
|
|
227
313
|
}
|
|
228
314
|
if run_id:
|
|
229
315
|
interrupt["run_id"] = str(run_id)
|
ksadk/tools/result_budget.py
CHANGED
|
@@ -10,7 +10,6 @@ from uuid import uuid4
|
|
|
10
10
|
|
|
11
11
|
from ksadk.sessions.local_service import resolve_local_session_dir
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
_SAFE_NAME_RE = re.compile(r"[^A-Za-z0-9_.-]+")
|
|
15
14
|
|
|
16
15
|
|
|
@@ -58,7 +57,10 @@ def budget_tool_output(
|
|
|
58
57
|
active_budget = budget or default_tool_result_budget()
|
|
59
58
|
text, mime_type, extension = _stringify_value(value)
|
|
60
59
|
original_chars = len(text)
|
|
61
|
-
should_persist =
|
|
60
|
+
should_persist = (
|
|
61
|
+
original_chars > active_budget.persist_threshold_chars
|
|
62
|
+
or original_chars > active_budget.max_chars
|
|
63
|
+
)
|
|
62
64
|
preview_limit = max(0, min(active_budget.preview_chars, active_budget.max_chars))
|
|
63
65
|
preview = text[:preview_limit] if should_persist else text[: active_budget.max_chars]
|
|
64
66
|
result: dict[str, Any] = {
|
|
@@ -126,7 +128,9 @@ def _persist_tool_output(
|
|
|
126
128
|
or metadata.get("id")
|
|
127
129
|
or uuid4().hex
|
|
128
130
|
)
|
|
129
|
-
stem = _safe_filename(f"{tool_use_id}.{field_name}") or _safe_filename(
|
|
131
|
+
stem = _safe_filename(f"{tool_use_id}.{field_name}") or _safe_filename(
|
|
132
|
+
f"{tool_name}.{field_name}.{uuid4().hex}"
|
|
133
|
+
)
|
|
130
134
|
path = (persist_dir / f"{stem}.{extension}").resolve()
|
|
131
135
|
if persist_dir not in path.parents and path != persist_dir:
|
|
132
136
|
raise ValueError("tool result path must stay inside persist_dir")
|
|
@@ -137,7 +141,11 @@ def _persist_tool_output(
|
|
|
137
141
|
def _stringify_value(value: Any) -> tuple[str, str, str]:
|
|
138
142
|
if isinstance(value, str):
|
|
139
143
|
return value, "text/plain", "txt"
|
|
140
|
-
return
|
|
144
|
+
return (
|
|
145
|
+
json.dumps(value, ensure_ascii=False, indent=2, sort_keys=True),
|
|
146
|
+
"application/json",
|
|
147
|
+
"json",
|
|
148
|
+
)
|
|
141
149
|
|
|
142
150
|
|
|
143
151
|
def _safe_filename(value: str) -> str:
|