agentengine-sdk-python 0.6.2__py3-none-any.whl → 0.6.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.6.9.dist-info/METADATA +179 -0
- agentengine_sdk_python-0.6.9.dist-info/RECORD +487 -0
- {agentengine_sdk_python-0.6.2.dist-info → agentengine_sdk_python-0.6.9.dist-info}/WHEEL +1 -1
- agentengine_sdk_python-0.6.9.dist-info/entry_points.txt +3 -0
- agentengine_sdk_python-0.6.9.dist-info/licenses/LICENSE +175 -0
- agentengine_sdk_python-0.6.9.dist-info/top_level.txt +2 -0
- ksadk/__init__.py +13 -0
- ksadk/__main__.py +4 -0
- ksadk/a2a/__init__.py +15 -0
- ksadk/a2a/card_builder.py +64 -0
- ksadk/a2a/client.py +309 -0
- ksadk/a2a/executor.py +201 -0
- ksadk/a2a/server.py +79 -0
- ksadk/agents/__init__.py +20 -0
- ksadk/agents/base.py +370 -0
- ksadk/agents/context.py +38 -0
- ksadk/agents/event.py +35 -0
- ksadk/agents/loop_agent.py +71 -0
- ksadk/agents/parallel_agent.py +109 -0
- ksadk/agents/runner_adapter.py +24 -0
- ksadk/agents/sequential_agent.py +34 -0
- ksadk/api/__init__.py +3 -0
- ksadk/api/client.py +2227 -0
- ksadk/builders/__init__.py +20 -0
- ksadk/builders/base.py +66 -0
- ksadk/builders/code_builder.py +1990 -0
- ksadk/builders/container_builder.py +786 -0
- ksadk/builders/framework_requirements.py +59 -0
- ksadk/builders/ks3_uploader.py +389 -0
- ksadk/builders/mcp_builder.py +476 -0
- ksadk/builders/requirements_utils.py +75 -0
- ksadk/cli/__init__.py +531 -0
- ksadk/cli/__main__.py +4 -0
- ksadk/cli/agent_ref.py +204 -0
- ksadk/cli/cmd_a2a.py +167 -0
- ksadk/cli/cmd_agent.py +201 -0
- ksadk/cli/cmd_build.py +270 -0
- ksadk/cli/cmd_completion.py +304 -0
- ksadk/cli/cmd_config.py +758 -0
- ksadk/cli/cmd_create.py +2277 -0
- ksadk/cli/cmd_dashboard.py +900 -0
- ksadk/cli/cmd_deploy.py +704 -0
- ksadk/cli/cmd_destroy.py +345 -0
- ksadk/cli/cmd_files.py +1227 -0
- ksadk/cli/cmd_hermes.py +1259 -0
- ksadk/cli/cmd_invoke.py +1336 -0
- ksadk/cli/cmd_launch.py +564 -0
- ksadk/cli/cmd_mcp.py +1174 -0
- ksadk/cli/cmd_model.py +302 -0
- ksadk/cli/cmd_openclaw.py +3918 -0
- ksadk/cli/cmd_run.py +232 -0
- ksadk/cli/cmd_status.py +588 -0
- ksadk/cli/cmd_version.py +522 -0
- ksadk/cli/cmd_web.py +288 -0
- ksadk/cli/deploy_utils.py +87 -0
- ksadk/cli/dry_run.py +214 -0
- ksadk/cli/env_options.py +82 -0
- ksadk/cli/error_utils.py +525 -0
- ksadk/cli/global_options.py +31 -0
- ksadk/cli/local_runtime.py +97 -0
- ksadk/cli/model_catalog.py +136 -0
- ksadk/cli/network_options.py +410 -0
- ksadk/cli/resource_common.py +621 -0
- ksadk/cli/storage.py +84 -0
- ksadk/cli/ui.py +431 -0
- ksadk/cli/workflow_common.py +552 -0
- ksadk/common/__init__.py +14 -0
- ksadk/common/aicp_env.py +128 -0
- ksadk/common/auth.py +190 -0
- ksadk/common/constants.py +84 -0
- ksadk/common/llm_utils.py +61 -0
- ksadk/configs/__init__.py +61 -0
- ksadk/configs/env_registry.py +342 -0
- ksadk/configs/global_config.py +200 -0
- ksadk/configs/settings.py +706 -0
- ksadk/conversations/__init__.py +95 -0
- ksadk/conversations/attachment_storage.py +379 -0
- ksadk/conversations/attachments.py +774 -0
- ksadk/conversations/compaction_pipeline.py +387 -0
- ksadk/conversations/compaction_prompt.py +128 -0
- ksadk/conversations/context.py +303 -0
- ksadk/conversations/model_context.py +360 -0
- ksadk/conversations/model_options.py +136 -0
- ksadk/conversations/normalize.py +446 -0
- ksadk/conversations/reasoning_markup.py +91 -0
- ksadk/conversations/run_kinds.py +61 -0
- ksadk/conversations/run_status.py +53 -0
- ksadk/conversations/runtime.py +5208 -0
- ksadk/conversations/semantic_summary.py +359 -0
- ksadk/conversations/session_title.py +254 -0
- ksadk/deployment/__init__.py +83 -0
- ksadk/deployment/agent_access.py +226 -0
- ksadk/deployment/base.py +229 -0
- ksadk/deployment/manager.py +332 -0
- ksadk/deployment/providers/__init__.py +10 -0
- ksadk/deployment/providers/serverless.py +1105 -0
- ksadk/deployment/registry.py +120 -0
- ksadk/deployment/state.py +78 -0
- ksadk/deployment/ui_config.py +21 -0
- ksadk/detection/__init__.py +7 -0
- ksadk/detection/detector.py +431 -0
- ksadk/detection/mcp_detector.py +250 -0
- ksadk/hermes_terminal.py +467 -0
- ksadk/identity/__init__.py +17 -0
- ksadk/identity/resolver.py +385 -0
- ksadk/knowledge_base/__init__.py +62 -0
- ksadk/knowledge_base/adk_tool.py +47 -0
- ksadk/knowledge_base/client.py +297 -0
- ksadk/knowledge_base/langchain_tool.py +55 -0
- ksadk/knowledge_base/service.py +66 -0
- ksadk/knowledge_base/tool.py +50 -0
- ksadk/markdown.py +169 -0
- ksadk/mcp_runtime/__init__.py +231 -0
- ksadk/memory/__init__.py +57 -0
- ksadk/memory/adk/__init__.py +51 -0
- ksadk/memory/adk/backends/__init__.py +5 -0
- ksadk/memory/adk/backends/base_ltm_backend.py +52 -0
- ksadk/memory/adk/backends/http_ltm_backend.py +183 -0
- ksadk/memory/adk/backends/inmemory_ltm_backend.py +96 -0
- ksadk/memory/adk/backends/sdk_ltm_backend.py +456 -0
- ksadk/memory/adk/long_term_memory.py +273 -0
- ksadk/memory/adk/short_term_memory.py +289 -0
- ksadk/memory/adk_tool.py +31 -0
- ksadk/memory/backends/__init__.py +6 -0
- ksadk/memory/backends/base.py +103 -0
- ksadk/memory/backends/memory.py +112 -0
- ksadk/memory/backends/redis.py +146 -0
- ksadk/memory/langchain_tool.py +39 -0
- ksadk/memory/ltm_backend_factory.py +24 -0
- ksadk/memory/manager.py +215 -0
- ksadk/memory/service.py +172 -0
- ksadk/memory/tool.py +96 -0
- ksadk/model_policy.py +223 -0
- ksadk/openclaw_gateway.py +378 -0
- ksadk/runners/__init__.py +8 -0
- ksadk/runners/adk_runner.py +1135 -0
- ksadk/runners/base_runner.py +305 -0
- ksadk/runners/deepagents_runner.py +13 -0
- ksadk/runners/factory.py +73 -0
- ksadk/runners/langchain_runner.py +539 -0
- ksadk/runners/langgraph_runner.py +852 -0
- ksadk/runners/patch_langchain.py +187 -0
- ksadk/runners/remote_runner.py +667 -0
- ksadk/runners/usage_accumulator.py +38 -0
- ksadk/runners/utils/__init__.py +19 -0
- ksadk/runners/utils/langfuse.py +230 -0
- ksadk/runners/utils/loader.py +62 -0
- ksadk/runtime_context.py +166 -0
- ksadk/runtime_state.py +25 -0
- ksadk/sandbox/__init__.py +28 -0
- ksadk/sandbox/backends/__init__.py +9 -0
- ksadk/sandbox/backends/e2b.py +154 -0
- ksadk/sandbox/backends/local_process.py +131 -0
- ksadk/sandbox/base.py +101 -0
- ksadk/sandbox/factory.py +53 -0
- ksadk/sandbox/registry.py +187 -0
- ksadk/server/__init__.py +7 -0
- ksadk/server/api_models.py +73 -0
- ksadk/server/app.py +3789 -0
- ksadk/server/static/assets/ArtifactsPanel-C0meuOdi.js +1 -0
- ksadk/server/static/assets/CodeBlock-BbI4HPtJ.js +9 -0
- ksadk/server/static/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- ksadk/server/static/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- ksadk/server/static/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- ksadk/server/static/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- ksadk/server/static/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- ksadk/server/static/assets/MathMessageMarkdown-DMLQYoLp.js +8 -0
- ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +1 -0
- ksadk/server/static/assets/MermaidBlock-DCR8WZ17.js +303 -0
- ksadk/server/static/assets/NativeTerminalPanel-CHOd7Rch.css +1 -0
- ksadk/server/static/assets/NativeTerminalPanel-CKUvWhUz.js +1 -0
- ksadk/server/static/assets/addon-fit-DthTIhi3.js +1 -0
- ksadk/server/static/assets/apl-CnwPGSsG.js +1 -0
- ksadk/server/static/assets/arc-bj2rZnP5.js +1 -0
- ksadk/server/static/assets/architecture-7EHR7CIX-Cr6Xz1_c.js +1 -0
- ksadk/server/static/assets/architectureDiagram-3BPJPVTR-2u1ltDIj.js +36 -0
- ksadk/server/static/assets/asciiarmor-qTkVPQu6.js +1 -0
- ksadk/server/static/assets/asn1-Dr8qZg38.js +1 -0
- ksadk/server/static/assets/asterisk-Bja0s6e1.js +1 -0
- ksadk/server/static/assets/blockDiagram-GPEHLZMM-D6fvdK20.js +132 -0
- ksadk/server/static/assets/brainfuck-D5EjA2JK.js +1 -0
- ksadk/server/static/assets/c4Diagram-AAUBKEIU-BK82L5n5.js +10 -0
- ksadk/server/static/assets/channel-BSSOwFIb.js +1 -0
- ksadk/server/static/assets/chunk-2J33WTMH-DLVdkeyQ.js +1 -0
- ksadk/server/static/assets/chunk-4BX2VUAB-BbwsYcbW.js +1 -0
- ksadk/server/static/assets/chunk-55IACEB6-DOairxzw.js +1 -0
- ksadk/server/static/assets/chunk-727SXJPM-hCO487gs.js +206 -0
- ksadk/server/static/assets/chunk-AQP2D5EJ-XU8vDOuG.js +231 -0
- ksadk/server/static/assets/chunk-FMBD7UC4-PrapyfMu.js +15 -0
- ksadk/server/static/assets/chunk-ND2GUHAM-CboKhTZ3.js +1 -0
- ksadk/server/static/assets/chunk-QZHKN3VN-XXpdiwUL.js +1 -0
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-C5HvGiyK.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-C5HvGiyK.js +1 -0
- ksadk/server/static/assets/clike-DHH8Ad3s.js +1 -0
- ksadk/server/static/assets/clojure-BflJGmDX.js +1 -0
- ksadk/server/static/assets/cmake-CyVbuzPu.js +1 -0
- ksadk/server/static/assets/cobol-B_OZ4V-R.js +1 -0
- ksadk/server/static/assets/coffeescript-B2pKbFk8.js +1 -0
- ksadk/server/static/assets/commonlisp-CcllspGY.js +1 -0
- ksadk/server/static/assets/cose-bilkent-S5V4N54A-_N8bJ-EU.js +1 -0
- ksadk/server/static/assets/crystal-M5-qzICs.js +1 -0
- ksadk/server/static/assets/css-CYpP4FRV.js +1 -0
- ksadk/server/static/assets/cypher-p9eYesGn.js +1 -0
- ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +321 -0
- ksadk/server/static/assets/d-BhMjBjQP.js +1 -0
- ksadk/server/static/assets/dagre-BM42HDAG-FoDlo5J2.js +4 -0
- ksadk/server/static/assets/dagre-Bx709z4p.js +1 -0
- ksadk/server/static/assets/defaultLocale-C8Fc0cco.js +1 -0
- ksadk/server/static/assets/diagram-2AECGRRQ-BBp6ebBw.js +43 -0
- ksadk/server/static/assets/diagram-5GNKFQAL-CqOvG1PR.js +10 -0
- ksadk/server/static/assets/diagram-KO2AKTUF-O9T3t6ba.js +3 -0
- ksadk/server/static/assets/diagram-LMA3HP47-CGG8ekBO.js +24 -0
- ksadk/server/static/assets/diagram-OG6HWLK6-4BmH1EEg.js +24 -0
- ksadk/server/static/assets/diff-ChtP43wD.js +1 -0
- ksadk/server/static/assets/dist-6kSZvCZh.js +1 -0
- ksadk/server/static/assets/dist-B67uF2uK.js +1 -0
- ksadk/server/static/assets/dist-BMKM66B4.js +1 -0
- ksadk/server/static/assets/dist-BVzcWa6D.js +1 -0
- ksadk/server/static/assets/dist-Bk1l05Ni.js +1 -0
- ksadk/server/static/assets/dist-BkJjNih3.js +1 -0
- ksadk/server/static/assets/dist-BmuTWcm7.js +9 -0
- ksadk/server/static/assets/dist-C2DKRFVK.js +1 -0
- ksadk/server/static/assets/dist-CWiTDN_V.js +6 -0
- ksadk/server/static/assets/dist-CZ6C3x8B.js +23 -0
- ksadk/server/static/assets/dist-CiZHB6ZW.js +1 -0
- ksadk/server/static/assets/dist-Cp1_jKwf.js +1 -0
- ksadk/server/static/assets/dist-Cwhk4lwI.js +2 -0
- ksadk/server/static/assets/dist-D5JGcxBx.js +11 -0
- ksadk/server/static/assets/dist-D99wf6_X.js +1 -0
- ksadk/server/static/assets/dist-DCpZrjaK.js +1 -0
- ksadk/server/static/assets/dist-DI-oVAXw.js +1 -0
- ksadk/server/static/assets/dist-DLMjL01k.js +1 -0
- ksadk/server/static/assets/dist-DLeM1OCK.js +1 -0
- ksadk/server/static/assets/dist-DM0rEQPk.js +1 -0
- ksadk/server/static/assets/dist-DbaH3p5h.js +1 -0
- ksadk/server/static/assets/dist-S4klkK5W.js +1 -0
- ksadk/server/static/assets/dockerfile-BLkNEvjs.js +1 -0
- ksadk/server/static/assets/dtd-DTF72YNO.js +1 -0
- ksadk/server/static/assets/dylan-C6jEEEk-.js +1 -0
- ksadk/server/static/assets/ebnf-D4c0_ac3.js +1 -0
- ksadk/server/static/assets/ecl-BSZaIHnp.js +1 -0
- ksadk/server/static/assets/eiffel-BEjRio4Q.js +1 -0
- ksadk/server/static/assets/elm-Cshzl8qu.js +1 -0
- ksadk/server/static/assets/erDiagram-TEJ5UH35-oJhaci7S.js +85 -0
- ksadk/server/static/assets/erlang-DaB2Rkuy.js +1 -0
- ksadk/server/static/assets/eventmodeling-FCH6USID-CIgwHJLL.js +1 -0
- ksadk/server/static/assets/factor-D7LVTn2l.js +1 -0
- ksadk/server/static/assets/fcl-ClOhbFR7.js +1 -0
- ksadk/server/static/assets/flowDiagram-I6XJVG4X-DtTmUan-.js +162 -0
- ksadk/server/static/assets/forth-Cezjo90N.js +1 -0
- ksadk/server/static/assets/fortran-Bt6PBEDR.js +1 -0
- ksadk/server/static/assets/ganttDiagram-6RSMTGT7-BSsb_eij.js +292 -0
- ksadk/server/static/assets/gas-BHEdbvp9.js +1 -0
- ksadk/server/static/assets/gherkin-oBAE_ms0.js +1 -0
- ksadk/server/static/assets/gitGraph-WXDBUCRP-BVAJ7uo0.js +1 -0
- ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-BR5s6Pws.js +106 -0
- ksadk/server/static/assets/graphlib-B8gBHxth.js +1 -0
- ksadk/server/static/assets/groovy-BC3IOsC8.js +1 -0
- ksadk/server/static/assets/haskell-BRsoo5mP.js +1 -0
- ksadk/server/static/assets/haxe-DIz0ZZqd.js +1 -0
- ksadk/server/static/assets/http-CLVgA2GD.js +1 -0
- ksadk/server/static/assets/idl-BUZw3wgd.js +1 -0
- ksadk/server/static/assets/index-BH7-pC0B.js +165 -0
- ksadk/server/static/assets/index-DAURbCsP.css +1 -0
- ksadk/server/static/assets/info-J43DQDTF-MT80V4ge.js +1 -0
- ksadk/server/static/assets/infoDiagram-5YYISTIA-DYPc5cvh.js +2 -0
- ksadk/server/static/assets/init-D6jRqBbL.js +1 -0
- ksadk/server/static/assets/ishikawaDiagram-YF4QCWOH-MoBdALDg.js +70 -0
- ksadk/server/static/assets/javascript-9Tg8ixDm.js +1 -0
- ksadk/server/static/assets/journeyDiagram-JHISSGLW-DgLiQT8l.js +139 -0
- ksadk/server/static/assets/julia-CQfgDRfP.js +1 -0
- ksadk/server/static/assets/kanban-definition-UN3LZRKU-CsFx112F.js +89 -0
- ksadk/server/static/assets/katex-DRsiwpM2.js +265 -0
- ksadk/server/static/assets/linear-TNRQ5Orv.js +1 -0
- ksadk/server/static/assets/livescript-BXxG0Yva.js +1 -0
- ksadk/server/static/assets/lua-CiA1ziua.js +1 -0
- ksadk/server/static/assets/mathematica-u8YMmbU0.js +1 -0
- ksadk/server/static/assets/mbox-BEMVcqjs.js +1 -0
- ksadk/server/static/assets/mermaid-parser.core-D2eMVOgo.js +161 -0
- ksadk/server/static/assets/mindmap-definition-RKZ34NQL-BtByYFhL.js +96 -0
- ksadk/server/static/assets/mirc-C9zpzAZU.js +1 -0
- ksadk/server/static/assets/mllike-B45xgp2S.js +1 -0
- ksadk/server/static/assets/modelica-CqHI_q-D.js +1 -0
- ksadk/server/static/assets/mscgen-qgSLujhx.js +1 -0
- ksadk/server/static/assets/mumps-CW_TBmxz.js +1 -0
- ksadk/server/static/assets/nginx-BMaDbqW3.js +1 -0
- ksadk/server/static/assets/nsis-AQ_alPln.js +1 -0
- ksadk/server/static/assets/ntriples-d28e9m0E.js +1 -0
- ksadk/server/static/assets/octave-D2Q8cUp1.js +1 -0
- ksadk/server/static/assets/ordinal-hYBb2elL.js +1 -0
- ksadk/server/static/assets/oz-BwTct_5T.js +1 -0
- ksadk/server/static/assets/packet-YPE3B663-BLKhbXZB.js +1 -0
- ksadk/server/static/assets/pascal-Dp_KdFgX.js +1 -0
- ksadk/server/static/assets/perl-CdEHsPfU.js +1 -0
- ksadk/server/static/assets/pie-LRSECV5Y-DFOikjSY.js +1 -0
- ksadk/server/static/assets/pieDiagram-4H26LBE5-DPnuCB8c.js +30 -0
- ksadk/server/static/assets/pig-AF4Hwhju.js +1 -0
- ksadk/server/static/assets/powershell-CzG71I4L.js +1 -0
- ksadk/server/static/assets/properties-C357ku5U.js +1 -0
- ksadk/server/static/assets/protobuf-D1ij_kNL.js +1 -0
- ksadk/server/static/assets/pug-Bugr-47h.js +1 -0
- ksadk/server/static/assets/puppet-B4hC2X4m.js +1 -0
- ksadk/server/static/assets/python-BqYw9LYJ.js +1 -0
- ksadk/server/static/assets/q-B9NhS7L_.js +1 -0
- ksadk/server/static/assets/quadrantDiagram-W4KKPZXB-miFpCPv4.js +7 -0
- ksadk/server/static/assets/r-DADKenSm.js +1 -0
- ksadk/server/static/assets/radar-GUYGQ44K-095b1Ikw.js +1 -0
- ksadk/server/static/assets/requirementDiagram-4Y6WPE33-mjB_yYkW.js +84 -0
- ksadk/server/static/assets/rpm-gpDK5sbt.js +1 -0
- ksadk/server/static/assets/ruby-DsYpTuWg.js +1 -0
- ksadk/server/static/assets/sankeyDiagram-5OEKKPKP-D7hSlZZZ.js +40 -0
- ksadk/server/static/assets/sas-C2OyD2Y6.js +1 -0
- ksadk/server/static/assets/scheme-CyDdOh7e.js +1 -0
- ksadk/server/static/assets/sequenceDiagram-3UESZ5HK-D9Cx6hC3.js +162 -0
- ksadk/server/static/assets/shell-Du5Qg9im.js +1 -0
- ksadk/server/static/assets/sieve-BAxa3IjF.js +1 -0
- ksadk/server/static/assets/simple-mode-DRpGK0lJ.js +1 -0
- ksadk/server/static/assets/smalltalk-BLp5-jwC.js +1 -0
- ksadk/server/static/assets/solr-BBopId9w.js +1 -0
- ksadk/server/static/assets/sparql-Dz-mlCAC.js +1 -0
- ksadk/server/static/assets/spreadsheet-CTIncYxj.js +1 -0
- ksadk/server/static/assets/sql-DcCJ9jop.js +1 -0
- ksadk/server/static/assets/stateDiagram-AJRCARHV-D_zrg47o.js +1 -0
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-J9kCb0nC.js +1 -0
- ksadk/server/static/assets/stex-sDrdk2BW.js +1 -0
- ksadk/server/static/assets/stylus-DLLZ8dgm.js +1 -0
- ksadk/server/static/assets/swift-DKB6_1j6.js +1 -0
- ksadk/server/static/assets/tcl-BGfruO1u.js +1 -0
- ksadk/server/static/assets/textile-DWBqthVk.js +1 -0
- ksadk/server/static/assets/tiddlywiki-VlUiK86J.js +1 -0
- ksadk/server/static/assets/tiki-CxVlf5KZ.js +1 -0
- ksadk/server/static/assets/timeline-definition-PNZ67QCA-CwSec0Wa.js +120 -0
- ksadk/server/static/assets/toml-LvoKBwCs.js +1 -0
- ksadk/server/static/assets/treeView-BLDUP644-yinfJEY6.js +1 -0
- ksadk/server/static/assets/treemap-LRROVOQU-DosUqN1Q.js +1 -0
- ksadk/server/static/assets/troff-C2dAgh7P.js +1 -0
- ksadk/server/static/assets/ttcn-BePYh-hG.js +1 -0
- ksadk/server/static/assets/ttcn-cfg-CY0aot7Q.js +1 -0
- ksadk/server/static/assets/turtle-BDLWE2cD.js +1 -0
- ksadk/server/static/assets/vb-BthdM_4N.js +1 -0
- ksadk/server/static/assets/vbscript-D9f6rSsU.js +1 -0
- ksadk/server/static/assets/velocity-CqftRsjg.js +1 -0
- ksadk/server/static/assets/vennDiagram-CIIHVFJN-agCVobiF.js +34 -0
- ksadk/server/static/assets/verilog-D-x6ne0Z.js +1 -0
- ksadk/server/static/assets/vhdl-CMrOq2q1.js +1 -0
- ksadk/server/static/assets/wardley-L42UT6IY-Bvp7-5uH.js +1 -0
- ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-TmrlhWNt.js +78 -0
- ksadk/server/static/assets/webidl-D5jiJvOU.js +1 -0
- ksadk/server/static/assets/xquery-fj_R-kMw.js +1 -0
- ksadk/server/static/assets/xterm-DooSxjI5.js +36 -0
- ksadk/server/static/assets/xychartDiagram-2RQKCTM6-DV71V-ah.js +7 -0
- ksadk/server/static/assets/yacas-CXXgtw0p.js +1 -0
- ksadk/server/static/assets/z80-CL1naaMV.js +1 -0
- ksadk/server/static/favicon.svg +1 -0
- ksadk/server/static/icons.svg +24 -0
- ksadk/server/static/index.html +14 -0
- ksadk/server/terminal_sessions.py +551 -0
- ksadk/sessions/__init__.py +283 -0
- ksadk/sessions/base.py +354 -0
- ksadk/sessions/continuity.py +313 -0
- ksadk/sessions/errors.py +7 -0
- ksadk/sessions/in_memory.py +273 -0
- ksadk/sessions/local_service.py +949 -0
- ksadk/sessions/postgres_service.py +838 -0
- ksadk/sessions/sqlite_service.py +13 -0
- ksadk/skills/__init__.py +9 -0
- ksadk/skills/loader.py +46 -0
- ksadk/skills/models.py +120 -0
- ksadk/skills/package_store.py +104 -0
- ksadk/skills/runtime/__init__.py +17 -0
- ksadk/skills/runtime/agent.py +183 -0
- ksadk/skills/runtime/artifacts.py +39 -0
- ksadk/skills/runtime/backends/__init__.py +1 -0
- ksadk/skills/runtime/backends/disabled.py +8 -0
- ksadk/skills/runtime/backends/e2b.py +168 -0
- ksadk/skills/runtime/backends/local.py +95 -0
- ksadk/skills/runtime/base.py +103 -0
- ksadk/skills/runtime/executor.py +219 -0
- ksadk/skills/runtime/factory.py +37 -0
- ksadk/skills/runtime/loader.py +131 -0
- ksadk/skills/runtime/registry.py +150 -0
- ksadk/skills/runtime/request.py +67 -0
- ksadk/skills/service_client.py +239 -0
- ksadk/skills/service_env.py +58 -0
- ksadk/skills/tool_defs.py +221 -0
- ksadk/terminal_client.py +69 -0
- ksadk/terminal_exec_policy.py +229 -0
- ksadk/tools/__init__.py +17 -0
- ksadk/tools/gateway.py +230 -0
- ksadk/tools/result_budget.py +154 -0
- ksadk/toolsets/__init__.py +852 -0
- ksadk/toolsets/_langchain.py +11 -0
- ksadk/toolsets/platform.py +93 -0
- ksadk/toolsets/sandbox.py +310 -0
- ksadk/toolsets/skills.py +217 -0
- ksadk/toolsets/web.py +266 -0
- ksadk/toolsets/workspace.py +878 -0
- ksadk/toolsets/workspace_state.py +44 -0
- ksadk/tracing/__init__.py +37 -0
- ksadk/tracing/exporters/__init__.py +1 -0
- ksadk/tracing/exporters/inmemory_exporter.py +116 -0
- ksadk/tracing/exporters/langfuse_exporter.py +445 -0
- ksadk/tracing/setup.py +829 -0
- ksadk/tracing/span_utils.py +114 -0
- ksadk/tui/__init__.py +12 -0
- ksadk/tui/app.py +400 -0
- ksadk/tui/clipboard.py +100 -0
- ksadk/tui/widgets/__init__.py +22 -0
- ksadk/tui/widgets/assistant.py +89 -0
- ksadk/tui/widgets/base.py +54 -0
- ksadk/tui/widgets/chat_input.py +246 -0
- ksadk/tui/widgets/history.py +156 -0
- ksadk/tui/widgets/system.py +87 -0
- ksadk/tui/widgets/thinking.py +110 -0
- ksadk/tui/widgets/tool_call.py +161 -0
- ksadk/tui/widgets/user.py +37 -0
- ksadk/ui_config.py +168 -0
- ksadk/version.py +4 -0
- ksadk_runtime_common/__init__.py +20 -0
- ksadk_runtime_common/memory_backend/__init__.py +29 -0
- ksadk_runtime_common/memory_backend/manifest.py +79 -0
- ksadk_runtime_common/memory_backend/providers/__init__.py +6 -0
- ksadk_runtime_common/memory_backend/providers/lancedb.py +151 -0
- ksadk_runtime_common/memory_backend/providers/mem0.py +74 -0
- ksadk_runtime_common/memory_backend/registry.py +56 -0
- ksadk_runtime_common/memory_backend/render.py +71 -0
- ksadk_runtime_common/schemas/memory_backend_manifest.schema.json +148 -0
- ksadk_runtime_common/workspace_files/__init__.py +29 -0
- ksadk_runtime_common/workspace_files/bootstrap.py +56 -0
- ksadk_runtime_common/workspace_files/constants.py +9 -0
- ksadk_runtime_common/workspace_files/path_utils.py +71 -0
- ksadk_runtime_common/workspace_files/preview.py +96 -0
- ksadk_runtime_common/workspace_files/router.py +254 -0
- agentengine_sdk_python-0.6.2.dist-info/METADATA +0 -46
- agentengine_sdk_python-0.6.2.dist-info/RECORD +0 -4
- agentengine_sdk_python-0.6.2.dist-info/top_level.txt +0 -1
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from typing import Any, Dict, Iterable, List
|
|
6
|
+
|
|
7
|
+
from ksadk.sessions.base import SessionEvent
|
|
8
|
+
|
|
9
|
+
CANONICAL_EVENT_TYPES = {
|
|
10
|
+
"user_message",
|
|
11
|
+
"assistant_message",
|
|
12
|
+
"tool_call",
|
|
13
|
+
"tool_result",
|
|
14
|
+
"approval_request",
|
|
15
|
+
"approval_response",
|
|
16
|
+
"attachment_ref",
|
|
17
|
+
"reasoning",
|
|
18
|
+
"run_status",
|
|
19
|
+
"run_checkpoint",
|
|
20
|
+
"run_resume",
|
|
21
|
+
"context_checkpoint",
|
|
22
|
+
"compaction_boundary",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
TRANSCRIPT_EVENT_TYPES = {
|
|
26
|
+
"user_message",
|
|
27
|
+
"assistant_message",
|
|
28
|
+
"tool_call",
|
|
29
|
+
"tool_result",
|
|
30
|
+
"approval_request",
|
|
31
|
+
"approval_response",
|
|
32
|
+
"attachment_ref",
|
|
33
|
+
"context_checkpoint",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
DATA_URL_RE = re.compile(
|
|
37
|
+
r"data:(?P<mime>[A-Za-z0-9.+-]+/[A-Za-z0-9.+-]+);base64,[A-Za-z0-9+/=_-]+"
|
|
38
|
+
)
|
|
39
|
+
BASE64_FIELD_RE = re.compile(
|
|
40
|
+
r"(?P<prefix>['\"](?P<field>file_data|data|bytes|base64)['\"]\s*:\s*['\"])(?P<value>[A-Za-z0-9+/=_-]{512,})(?P<suffix>['\"])",
|
|
41
|
+
re.IGNORECASE,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def sanitize_event_text_for_context(text: Any) -> str:
|
|
46
|
+
"""Return a compact text view for history/compaction without inline binaries."""
|
|
47
|
+
value = str(text or "")
|
|
48
|
+
if not value:
|
|
49
|
+
return ""
|
|
50
|
+
|
|
51
|
+
def _replace_data_url(match: re.Match[str]) -> str:
|
|
52
|
+
mime = match.group("mime")
|
|
53
|
+
media_type = "image" if mime.startswith("image/") else "file"
|
|
54
|
+
return f"[{media_type}: {mime} data-url omitted]"
|
|
55
|
+
|
|
56
|
+
value = DATA_URL_RE.sub(_replace_data_url, value)
|
|
57
|
+
value = BASE64_FIELD_RE.sub(
|
|
58
|
+
lambda match: (
|
|
59
|
+
f"{match.group('prefix')}[base64 {match.group('field')} omitted]"
|
|
60
|
+
f"{match.group('suffix')}"
|
|
61
|
+
),
|
|
62
|
+
value,
|
|
63
|
+
)
|
|
64
|
+
return value
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def extract_event_text(event: SessionEvent) -> str:
|
|
68
|
+
"""从结构化事件里提取最适合喂给模型的文本视图。
|
|
69
|
+
|
|
70
|
+
这里优先取 `agent_input`,因为它通常比展示给 UI 的 display text 更接近
|
|
71
|
+
真实 prompt;如果没有,再退回到 parts/text。
|
|
72
|
+
"""
|
|
73
|
+
metadata = event.metadata or {}
|
|
74
|
+
if metadata.get("agent_input"):
|
|
75
|
+
return sanitize_event_text_for_context(metadata["agent_input"])
|
|
76
|
+
|
|
77
|
+
content = event.content or {}
|
|
78
|
+
text = content.get("text")
|
|
79
|
+
if text:
|
|
80
|
+
return sanitize_event_text_for_context(text)
|
|
81
|
+
|
|
82
|
+
return sanitize_event_text_for_context(extract_text_from_event_parts(content.get("parts") or []))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def canonical_event_type(
|
|
86
|
+
event_type: str | None,
|
|
87
|
+
*,
|
|
88
|
+
author: str = "",
|
|
89
|
+
role: str = "",
|
|
90
|
+
) -> str:
|
|
91
|
+
raw = str(event_type or "").strip().lower()
|
|
92
|
+
if raw in CANONICAL_EVENT_TYPES:
|
|
93
|
+
return raw
|
|
94
|
+
if raw in {"tool_use", "function_call"}:
|
|
95
|
+
return "tool_call"
|
|
96
|
+
if raw in {"tool_response", "function_response"}:
|
|
97
|
+
return "tool_result"
|
|
98
|
+
if raw in {"approval", "interrupt"}:
|
|
99
|
+
return "approval_request"
|
|
100
|
+
if raw in {"attachment", "file_ref", "file_reference"}:
|
|
101
|
+
return "attachment_ref"
|
|
102
|
+
if raw in {"checkpoint", "context_checkpoint"}:
|
|
103
|
+
return "context_checkpoint"
|
|
104
|
+
if raw in {"boundary", "compaction_boundary"}:
|
|
105
|
+
return "compaction_boundary"
|
|
106
|
+
if raw in {"status", "run_status"}:
|
|
107
|
+
return "run_status"
|
|
108
|
+
if raw in {"run_checkpoint", "runtime_checkpoint"}:
|
|
109
|
+
return "run_checkpoint"
|
|
110
|
+
if raw in {"run_resume", "runtime_resume"}:
|
|
111
|
+
return "run_resume"
|
|
112
|
+
if raw in {"assistant", "model"} or role in {"assistant", "model"} or author in {"assistant", "model"}:
|
|
113
|
+
return "assistant_message"
|
|
114
|
+
return "user_message"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def extract_text_from_event_parts(parts: List[Dict[str, Any]]) -> str:
|
|
118
|
+
segments: List[str] = []
|
|
119
|
+
for part in parts or []:
|
|
120
|
+
if isinstance(part, dict) and part.get("text"):
|
|
121
|
+
segments.append(_stringify_part_text(part["text"]))
|
|
122
|
+
return "\n".join(segments)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _stringify_part_text(value: Any) -> str:
|
|
126
|
+
if isinstance(value, dict):
|
|
127
|
+
preview = (
|
|
128
|
+
value.get("stdout")
|
|
129
|
+
or value.get("stderr")
|
|
130
|
+
or value.get("text")
|
|
131
|
+
or value.get("content")
|
|
132
|
+
or value.get("preview")
|
|
133
|
+
or ""
|
|
134
|
+
)
|
|
135
|
+
persisted = value.get("persisted")
|
|
136
|
+
if isinstance(persisted, dict) and persisted.get("path"):
|
|
137
|
+
mime_type = str(persisted.get("mime_type") or "text/plain")
|
|
138
|
+
suffix = f"\n[persisted-output] {persisted['path']} ({mime_type})"
|
|
139
|
+
return f"{preview}{suffix}".strip()
|
|
140
|
+
return json.dumps(value, ensure_ascii=False, sort_keys=True)
|
|
141
|
+
return str(value)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def build_request_history(messages: Iterable[Dict[str, Any]]) -> List[Dict[str, str]]:
|
|
145
|
+
history: List[Dict[str, str]] = []
|
|
146
|
+
for message in messages or []:
|
|
147
|
+
role = str(message.get("role") or "")
|
|
148
|
+
if role in {"assistant", "model"}:
|
|
149
|
+
role = "model"
|
|
150
|
+
elif role not in {"user", "model"}:
|
|
151
|
+
continue
|
|
152
|
+
content = str(message.get("content") or "")
|
|
153
|
+
if content:
|
|
154
|
+
history.append({"role": role, "content": content})
|
|
155
|
+
return history
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def compacted_until_seq_id(events: List[SessionEvent]) -> int:
|
|
159
|
+
"""读取最新 checkpoint 覆盖到哪一个 seq_id。"""
|
|
160
|
+
checkpoints = [event for event in events if canonical_event_type(event.event_type) == "context_checkpoint"]
|
|
161
|
+
if not checkpoints:
|
|
162
|
+
return 0
|
|
163
|
+
latest = checkpoints[-1]
|
|
164
|
+
return int((latest.metadata or {}).get("compacted_until_seq_id") or 0)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def group_events_by_api_round(events: List[SessionEvent]) -> List[List[SessionEvent]]:
|
|
168
|
+
"""按 invocation/轮次分组,保证压缩和 PTL 截断不会打断一整轮对话。"""
|
|
169
|
+
groups: List[List[SessionEvent]] = []
|
|
170
|
+
current_key: str | None = None
|
|
171
|
+
for event in events:
|
|
172
|
+
key = str(event.invocation_id or f"seq:{event.seq_id}")
|
|
173
|
+
if key != current_key:
|
|
174
|
+
groups.append([])
|
|
175
|
+
current_key = key
|
|
176
|
+
groups[-1].append(event)
|
|
177
|
+
return groups
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def summarize_event_groups(
|
|
181
|
+
groups: List[List[SessionEvent]],
|
|
182
|
+
*,
|
|
183
|
+
previous_summary: str = "",
|
|
184
|
+
) -> str:
|
|
185
|
+
"""把要折叠的旧轮次压成一段 checkpoint 文本。
|
|
186
|
+
|
|
187
|
+
这里没有直接照搬 Claude Code 的 LLM summarizer,而是先落一个可预测、
|
|
188
|
+
可恢复的结构化摘要骨架,后续再替换成真正的 summarize agent 也不需要改
|
|
189
|
+
event contract。
|
|
190
|
+
"""
|
|
191
|
+
lines: List[str] = []
|
|
192
|
+
if previous_summary:
|
|
193
|
+
lines.append(previous_summary)
|
|
194
|
+
lines.append("Earlier conversation summary:")
|
|
195
|
+
for group in groups:
|
|
196
|
+
snippets: List[str] = []
|
|
197
|
+
for event in group:
|
|
198
|
+
event_type = canonical_event_type(
|
|
199
|
+
event.event_type,
|
|
200
|
+
author=event.author,
|
|
201
|
+
role=str((event.content or {}).get("role") or ""),
|
|
202
|
+
)
|
|
203
|
+
if event_type not in TRANSCRIPT_EVENT_TYPES or event_type == "context_checkpoint":
|
|
204
|
+
continue
|
|
205
|
+
text = extract_event_text(event)
|
|
206
|
+
if not text:
|
|
207
|
+
continue
|
|
208
|
+
if event_type in {"assistant_message", "tool_call"}:
|
|
209
|
+
role = "assistant"
|
|
210
|
+
else:
|
|
211
|
+
role = "user"
|
|
212
|
+
snippets.append(f"{role}: {text[:180]}")
|
|
213
|
+
if snippets:
|
|
214
|
+
lines.append(" | ".join(snippets))
|
|
215
|
+
return "\n".join(line for line in lines if line).strip()
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def project_model_messages(
|
|
219
|
+
events: List[SessionEvent],
|
|
220
|
+
*,
|
|
221
|
+
assistant_role: str = "model",
|
|
222
|
+
) -> List[Dict[str, str]]:
|
|
223
|
+
"""把 append-only transcript 投影成运行时 history。
|
|
224
|
+
|
|
225
|
+
核心原则:
|
|
226
|
+
1. `context_checkpoint` 之前的正文不再重复展开。
|
|
227
|
+
2. `run_status` 这类 transport/control 事件不进入模型上下文。
|
|
228
|
+
3. tool/approval/attachment 仍保留成可解释的文本占位,避免状态丢失。
|
|
229
|
+
"""
|
|
230
|
+
projected: List[Dict[str, str]] = []
|
|
231
|
+
compacted_until = compacted_until_seq_id(events)
|
|
232
|
+
checkpoint = next(
|
|
233
|
+
(
|
|
234
|
+
event
|
|
235
|
+
for event in reversed(events)
|
|
236
|
+
if canonical_event_type(event.event_type) == "context_checkpoint"
|
|
237
|
+
),
|
|
238
|
+
None,
|
|
239
|
+
)
|
|
240
|
+
if checkpoint:
|
|
241
|
+
summary_text = extract_event_text(checkpoint)
|
|
242
|
+
if summary_text:
|
|
243
|
+
projected.append(
|
|
244
|
+
{
|
|
245
|
+
"role": assistant_role,
|
|
246
|
+
"content": summary_text,
|
|
247
|
+
}
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
for event in events:
|
|
251
|
+
event_type = canonical_event_type(
|
|
252
|
+
event.event_type,
|
|
253
|
+
author=event.author,
|
|
254
|
+
role=str((event.content or {}).get("role") or ""),
|
|
255
|
+
)
|
|
256
|
+
if event.seq_id <= compacted_until and event_type != "context_checkpoint":
|
|
257
|
+
continue
|
|
258
|
+
if event_type not in TRANSCRIPT_EVENT_TYPES:
|
|
259
|
+
continue
|
|
260
|
+
if event_type in {"context_checkpoint", "compaction_boundary"}:
|
|
261
|
+
continue
|
|
262
|
+
|
|
263
|
+
text = extract_event_text(event)
|
|
264
|
+
if not text:
|
|
265
|
+
continue
|
|
266
|
+
|
|
267
|
+
if event_type == "assistant_message":
|
|
268
|
+
role = assistant_role
|
|
269
|
+
elif event_type == "tool_call":
|
|
270
|
+
role = assistant_role
|
|
271
|
+
text = f"[tool_call] {text}"
|
|
272
|
+
elif event_type == "tool_result":
|
|
273
|
+
role = "user"
|
|
274
|
+
text = f"[tool_result] {text}"
|
|
275
|
+
elif event_type == "approval_request":
|
|
276
|
+
role = assistant_role
|
|
277
|
+
text = f"[approval_request] {text}"
|
|
278
|
+
elif event_type == "approval_response":
|
|
279
|
+
role = "user"
|
|
280
|
+
text = f"[approval_response] {text}"
|
|
281
|
+
elif event_type == "attachment_ref":
|
|
282
|
+
role = "user"
|
|
283
|
+
text = f"[attachment] {text}"
|
|
284
|
+
else:
|
|
285
|
+
role = "user"
|
|
286
|
+
|
|
287
|
+
if projected and projected[-1]["role"] == role:
|
|
288
|
+
projected[-1]["content"] = f"{projected[-1]['content']}\n{text}".strip()
|
|
289
|
+
else:
|
|
290
|
+
projected.append({"role": role, "content": text})
|
|
291
|
+
|
|
292
|
+
return projected
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def build_history_from_events(events: List[SessionEvent]) -> List[Dict[str, str]]:
|
|
296
|
+
"""本地 runner 使用的最终 history 视图。"""
|
|
297
|
+
history: List[Dict[str, str]] = []
|
|
298
|
+
for message in project_model_messages(events, assistant_role="model"):
|
|
299
|
+
role = str(message.get("role") or "")
|
|
300
|
+
content = str(message.get("content") or "")
|
|
301
|
+
if role in {"user", "model"} and content:
|
|
302
|
+
history.append({"role": role, "content": content})
|
|
303
|
+
return history
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
from typing import Any, Mapping
|
|
5
|
+
|
|
6
|
+
# 这组默认值对应当前金山云模型服务还未完全补齐 metadata 时的保底能力。
|
|
7
|
+
# 两周后上游接口扩展后,只需要继续往 normalize_model_metadata 里补映射,
|
|
8
|
+
# 前端和 runtime 都不需要改自己的消费方式。
|
|
9
|
+
DEFAULT_CONTEXT_WINDOW_TOKENS = 200_000
|
|
10
|
+
DEFAULT_MAX_INPUT_TOKENS = 200_000
|
|
11
|
+
DEFAULT_MAX_OUTPUT_TOKENS = 32_000
|
|
12
|
+
DEFAULT_MAX_REASONING_TOKENS = 32_000
|
|
13
|
+
DEFAULT_REQUESTS_PER_MINUTE = 500
|
|
14
|
+
DEFAULT_TOKENS_PER_MINUTE = 1_000_000
|
|
15
|
+
|
|
16
|
+
AUTOCOMPACT_SUMMARY_RESERVE_TOKENS = 20_000
|
|
17
|
+
AUTOCOMPACT_BUFFER_TOKENS = 13_000
|
|
18
|
+
|
|
19
|
+
DEFAULT_MODEL_CAPABILITIES = {
|
|
20
|
+
"function_calling": True,
|
|
21
|
+
"structured_output": True,
|
|
22
|
+
"context_caching": True,
|
|
23
|
+
"multimodal_input_image": False,
|
|
24
|
+
"multimodal_input_video": False,
|
|
25
|
+
"multimodal_input_file": False,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
DEFAULT_MODEL_LIMITS = {
|
|
29
|
+
"context_window_tokens": DEFAULT_CONTEXT_WINDOW_TOKENS,
|
|
30
|
+
"max_input_tokens": DEFAULT_MAX_INPUT_TOKENS,
|
|
31
|
+
"max_output_tokens": DEFAULT_MAX_OUTPUT_TOKENS,
|
|
32
|
+
"max_reasoning_tokens": DEFAULT_MAX_REASONING_TOKENS,
|
|
33
|
+
"rpm": DEFAULT_REQUESTS_PER_MINUTE,
|
|
34
|
+
"tpm": DEFAULT_TOKENS_PER_MINUTE,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
DEFAULT_MODEL_PRICING = {
|
|
38
|
+
"online_input_per_million": 4.0,
|
|
39
|
+
"online_output_per_million": 18.0,
|
|
40
|
+
"batch_input_per_million": 2.0,
|
|
41
|
+
"batch_output_per_million": 9.0,
|
|
42
|
+
"online_cache_hit_input_per_million": 1.0,
|
|
43
|
+
"batch_cache_hit_input_per_million": 1.0,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _coerce_positive_int(value: Any) -> int | None:
|
|
48
|
+
if value is None or value == "":
|
|
49
|
+
return None
|
|
50
|
+
try:
|
|
51
|
+
parsed = int(value)
|
|
52
|
+
except (TypeError, ValueError):
|
|
53
|
+
return None
|
|
54
|
+
return parsed if parsed > 0 else None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _coerce_token_limit(value: Any, *, assume_k_for_plain_values: bool = False) -> int | None:
|
|
58
|
+
if value is None or value == "":
|
|
59
|
+
return None
|
|
60
|
+
if isinstance(value, (int, float)):
|
|
61
|
+
parsed = int(value)
|
|
62
|
+
if assume_k_for_plain_values and 0 < parsed <= 1000:
|
|
63
|
+
return parsed * 1000
|
|
64
|
+
return parsed if parsed > 0 else None
|
|
65
|
+
|
|
66
|
+
text = str(value).strip().lower().replace("_", "")
|
|
67
|
+
if not text:
|
|
68
|
+
return None
|
|
69
|
+
|
|
70
|
+
multiplier = 1
|
|
71
|
+
if text.endswith("k"):
|
|
72
|
+
multiplier = 1000
|
|
73
|
+
text = text[:-1]
|
|
74
|
+
elif text.endswith("m"):
|
|
75
|
+
multiplier = 1000 * 1000
|
|
76
|
+
text = text[:-1]
|
|
77
|
+
elif text.endswith("b"):
|
|
78
|
+
multiplier = 1000 * 1000 * 1000
|
|
79
|
+
text = text[:-1]
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
parsed = float(text)
|
|
83
|
+
except (TypeError, ValueError):
|
|
84
|
+
return None
|
|
85
|
+
if parsed <= 0:
|
|
86
|
+
return None
|
|
87
|
+
resolved = int(parsed * multiplier)
|
|
88
|
+
if multiplier == 1 and assume_k_for_plain_values and text.isdigit() and 0 < resolved <= 1000:
|
|
89
|
+
return resolved * 1000
|
|
90
|
+
return resolved
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _lookup(raw: Mapping[str, Any], *paths: str) -> Any:
|
|
94
|
+
"""按多条路径取 metadata,兼容未来上游字段逐步演进。"""
|
|
95
|
+
|
|
96
|
+
for path in paths:
|
|
97
|
+
current: Any = raw
|
|
98
|
+
found = True
|
|
99
|
+
for key in path.split("."):
|
|
100
|
+
if not isinstance(current, Mapping) or key not in current:
|
|
101
|
+
found = False
|
|
102
|
+
break
|
|
103
|
+
current = current[key]
|
|
104
|
+
if found and current is not None:
|
|
105
|
+
return current
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _normalize_modality_name(raw: Any) -> str:
|
|
110
|
+
text = str(raw or "").strip().lower()
|
|
111
|
+
if not text:
|
|
112
|
+
return ""
|
|
113
|
+
|
|
114
|
+
aliases = {
|
|
115
|
+
"文字": "text",
|
|
116
|
+
"文本": "text",
|
|
117
|
+
"text": "text",
|
|
118
|
+
"图片": "image",
|
|
119
|
+
"图像": "image",
|
|
120
|
+
"image": "image",
|
|
121
|
+
"视频": "video",
|
|
122
|
+
"video": "video",
|
|
123
|
+
"文件": "file",
|
|
124
|
+
"文档": "file",
|
|
125
|
+
"file": "file",
|
|
126
|
+
}
|
|
127
|
+
return aliases.get(text, text)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _extract_input_modalities(raw_model: Mapping[str, Any]) -> list[str]:
|
|
131
|
+
architecture = raw_model.get("architecture")
|
|
132
|
+
if not isinstance(architecture, Mapping):
|
|
133
|
+
return []
|
|
134
|
+
modalities = architecture.get("input_modalities")
|
|
135
|
+
if not isinstance(modalities, list):
|
|
136
|
+
return []
|
|
137
|
+
|
|
138
|
+
normalized: list[str] = []
|
|
139
|
+
for item in modalities:
|
|
140
|
+
value = _normalize_modality_name(item)
|
|
141
|
+
if value and value not in normalized:
|
|
142
|
+
normalized.append(value)
|
|
143
|
+
return normalized
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def supports_native_image_input(model_metadata: Mapping[str, Any] | None) -> bool:
|
|
147
|
+
if not isinstance(model_metadata, Mapping):
|
|
148
|
+
return False
|
|
149
|
+
capabilities = model_metadata.get("capabilities")
|
|
150
|
+
if isinstance(capabilities, Mapping) and capabilities.get("multimodal_input_image") is not None:
|
|
151
|
+
return bool(capabilities.get("multimodal_input_image"))
|
|
152
|
+
return "image" in _extract_input_modalities(model_metadata)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def estimate_text_tokens(text: str) -> int:
|
|
156
|
+
"""轻量 token 估算。
|
|
157
|
+
|
|
158
|
+
当前先做一层比 `len/4` 更稳的启发式:
|
|
159
|
+
- CJK 字符按 1 token 估算,避免中文场景长期卡在 0% / 1%
|
|
160
|
+
- 其他字符继续按 4 chars ~= 1 token 估算
|
|
161
|
+
|
|
162
|
+
这仍然不是真实 tokenizer,但比纯英文口径更接近本地中文使用体验。
|
|
163
|
+
后续如果上游或 runtime 有更准确 usage,可以在这里无缝替换。
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
stripped = str(text or "").strip()
|
|
167
|
+
if not stripped:
|
|
168
|
+
return 0
|
|
169
|
+
|
|
170
|
+
cjk_tokens = 0
|
|
171
|
+
ascii_chars = 0
|
|
172
|
+
for char in stripped:
|
|
173
|
+
codepoint = ord(char)
|
|
174
|
+
if (
|
|
175
|
+
0x3400 <= codepoint <= 0x4DBF
|
|
176
|
+
or 0x4E00 <= codepoint <= 0x9FFF
|
|
177
|
+
or 0xF900 <= codepoint <= 0xFAFF
|
|
178
|
+
):
|
|
179
|
+
cjk_tokens += 1
|
|
180
|
+
else:
|
|
181
|
+
ascii_chars += 1
|
|
182
|
+
return max(1, cjk_tokens + math.ceil(ascii_chars / 4))
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def get_effective_context_window_tokens(model_metadata: Mapping[str, Any] | None = None) -> int:
|
|
186
|
+
limits = dict(DEFAULT_MODEL_LIMITS)
|
|
187
|
+
if isinstance(model_metadata, Mapping):
|
|
188
|
+
limits.update(dict(model_metadata.get("limits") or {}))
|
|
189
|
+
if model_metadata.get("context_window_tokens"):
|
|
190
|
+
limits["context_window_tokens"] = model_metadata["context_window_tokens"]
|
|
191
|
+
if model_metadata.get("max_output_tokens"):
|
|
192
|
+
limits["max_output_tokens"] = model_metadata["max_output_tokens"]
|
|
193
|
+
|
|
194
|
+
context_window = _coerce_positive_int(limits.get("context_window_tokens")) or DEFAULT_CONTEXT_WINDOW_TOKENS
|
|
195
|
+
max_output_tokens = _coerce_positive_int(limits.get("max_output_tokens")) or DEFAULT_MAX_OUTPUT_TOKENS
|
|
196
|
+
reserved_tokens = min(max_output_tokens, AUTOCOMPACT_SUMMARY_RESERVE_TOKENS)
|
|
197
|
+
return max(1, context_window - reserved_tokens)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def get_auto_compact_threshold_tokens(model_metadata: Mapping[str, Any] | None = None) -> int:
|
|
201
|
+
effective_context_window = get_effective_context_window_tokens(model_metadata)
|
|
202
|
+
return max(1, effective_context_window - AUTOCOMPACT_BUFFER_TOKENS)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def get_auto_compact_threshold_percentage(model_metadata: Mapping[str, Any] | None = None) -> int:
|
|
206
|
+
context_window = (
|
|
207
|
+
_coerce_positive_int((model_metadata or {}).get("context_window_tokens"))
|
|
208
|
+
if isinstance(model_metadata, Mapping)
|
|
209
|
+
else None
|
|
210
|
+
) or DEFAULT_CONTEXT_WINDOW_TOKENS
|
|
211
|
+
threshold_tokens = get_auto_compact_threshold_tokens(model_metadata)
|
|
212
|
+
return max(0, min(100, int(round((threshold_tokens / context_window) * 100))))
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def normalize_model_metadata(raw_model: Mapping[str, Any] | str | None) -> dict[str, Any]:
|
|
216
|
+
"""把模型目录统一规范成稳定 shape。
|
|
217
|
+
|
|
218
|
+
设计目标:
|
|
219
|
+
1. 未来上游 metadata 扩展时,这里只需要补 alias 映射。
|
|
220
|
+
2. 当前前端/运行时只消费 canonical 字段,不直接依赖上游原始字段名。
|
|
221
|
+
3. 原始 dict 字段尽量保留,避免把未来有用的信息在本地这一层再次裁掉。
|
|
222
|
+
"""
|
|
223
|
+
|
|
224
|
+
base: dict[str, Any]
|
|
225
|
+
if isinstance(raw_model, Mapping):
|
|
226
|
+
base = dict(raw_model)
|
|
227
|
+
else:
|
|
228
|
+
base = {"id": str(raw_model or "unknown-model")}
|
|
229
|
+
|
|
230
|
+
model_id = str(base.get("id") or base.get("name") or "unknown-model")
|
|
231
|
+
display_name = str(base.get("display_name") or base.get("displayName") or model_id)
|
|
232
|
+
|
|
233
|
+
context_window_tokens = (
|
|
234
|
+
_coerce_token_limit(
|
|
235
|
+
_lookup(
|
|
236
|
+
base,
|
|
237
|
+
"context_window_tokens",
|
|
238
|
+
"metadata.context_window_tokens",
|
|
239
|
+
"limits.context_window_tokens",
|
|
240
|
+
"metadata.context_length",
|
|
241
|
+
"metadata.context_window",
|
|
242
|
+
"limits.context_length",
|
|
243
|
+
"limits.context_window",
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
or _coerce_token_limit(
|
|
247
|
+
_lookup(
|
|
248
|
+
base,
|
|
249
|
+
"context_length",
|
|
250
|
+
"context_window",
|
|
251
|
+
),
|
|
252
|
+
assume_k_for_plain_values=True,
|
|
253
|
+
)
|
|
254
|
+
or DEFAULT_CONTEXT_WINDOW_TOKENS
|
|
255
|
+
)
|
|
256
|
+
max_output_tokens = (
|
|
257
|
+
_coerce_token_limit(
|
|
258
|
+
_lookup(
|
|
259
|
+
base,
|
|
260
|
+
"max_output_tokens",
|
|
261
|
+
"metadata.max_output_tokens",
|
|
262
|
+
"limits.max_output_tokens",
|
|
263
|
+
"metadata.max_completion_tokens",
|
|
264
|
+
"metadata.max_tokens",
|
|
265
|
+
"limits.max_completion_tokens",
|
|
266
|
+
"limits.max_tokens",
|
|
267
|
+
)
|
|
268
|
+
)
|
|
269
|
+
or _coerce_token_limit(
|
|
270
|
+
_lookup(
|
|
271
|
+
base,
|
|
272
|
+
"max_completion_tokens",
|
|
273
|
+
"max_tokens",
|
|
274
|
+
),
|
|
275
|
+
assume_k_for_plain_values=True,
|
|
276
|
+
)
|
|
277
|
+
or DEFAULT_MAX_OUTPUT_TOKENS
|
|
278
|
+
)
|
|
279
|
+
max_input_tokens = (
|
|
280
|
+
_coerce_token_limit(
|
|
281
|
+
_lookup(
|
|
282
|
+
base,
|
|
283
|
+
"max_input_tokens",
|
|
284
|
+
"metadata.max_input_tokens",
|
|
285
|
+
"limits.max_input_tokens",
|
|
286
|
+
)
|
|
287
|
+
)
|
|
288
|
+
or _coerce_token_limit(
|
|
289
|
+
_lookup(
|
|
290
|
+
base,
|
|
291
|
+
"input_max_length",
|
|
292
|
+
),
|
|
293
|
+
assume_k_for_plain_values=True,
|
|
294
|
+
)
|
|
295
|
+
or DEFAULT_MAX_INPUT_TOKENS
|
|
296
|
+
)
|
|
297
|
+
max_reasoning_tokens = (
|
|
298
|
+
_coerce_token_limit(
|
|
299
|
+
_lookup(
|
|
300
|
+
base,
|
|
301
|
+
"max_reasoning_tokens",
|
|
302
|
+
"metadata.max_reasoning_tokens",
|
|
303
|
+
"limits.max_reasoning_tokens",
|
|
304
|
+
)
|
|
305
|
+
)
|
|
306
|
+
or _coerce_token_limit(
|
|
307
|
+
_lookup(
|
|
308
|
+
base,
|
|
309
|
+
"deep_thinking_max_length",
|
|
310
|
+
),
|
|
311
|
+
assume_k_for_plain_values=True,
|
|
312
|
+
)
|
|
313
|
+
or DEFAULT_MAX_REASONING_TOKENS
|
|
314
|
+
)
|
|
315
|
+
rpm = (
|
|
316
|
+
_coerce_positive_int(_lookup(base, "rpm", "metadata.rpm", "limits.rpm"))
|
|
317
|
+
or DEFAULT_REQUESTS_PER_MINUTE
|
|
318
|
+
)
|
|
319
|
+
tpm = (
|
|
320
|
+
_coerce_positive_int(_lookup(base, "tpm", "metadata.tpm", "limits.tpm"))
|
|
321
|
+
or DEFAULT_TOKENS_PER_MINUTE
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
input_modalities = _extract_input_modalities(base)
|
|
325
|
+
capabilities = {
|
|
326
|
+
**DEFAULT_MODEL_CAPABILITIES,
|
|
327
|
+
**dict(base.get("capabilities") or {}),
|
|
328
|
+
}
|
|
329
|
+
if input_modalities:
|
|
330
|
+
capabilities["multimodal_input_image"] = "image" in input_modalities
|
|
331
|
+
capabilities["multimodal_input_video"] = "video" in input_modalities
|
|
332
|
+
capabilities["multimodal_input_file"] = "file" in input_modalities
|
|
333
|
+
limits = {
|
|
334
|
+
**DEFAULT_MODEL_LIMITS,
|
|
335
|
+
**dict(base.get("limits") or {}),
|
|
336
|
+
"context_window_tokens": context_window_tokens,
|
|
337
|
+
"max_input_tokens": max_input_tokens,
|
|
338
|
+
"max_output_tokens": max_output_tokens,
|
|
339
|
+
"max_reasoning_tokens": max_reasoning_tokens,
|
|
340
|
+
"rpm": rpm,
|
|
341
|
+
"tpm": tpm,
|
|
342
|
+
}
|
|
343
|
+
pricing = {
|
|
344
|
+
**DEFAULT_MODEL_PRICING,
|
|
345
|
+
**dict(base.get("pricing") or {}),
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
normalized = {
|
|
349
|
+
**base,
|
|
350
|
+
"id": model_id,
|
|
351
|
+
"display_name": display_name,
|
|
352
|
+
"context_window_tokens": context_window_tokens,
|
|
353
|
+
"max_output_tokens": max_output_tokens,
|
|
354
|
+
"capabilities": capabilities,
|
|
355
|
+
"limits": limits,
|
|
356
|
+
"pricing": pricing,
|
|
357
|
+
}
|
|
358
|
+
normalized["auto_compact_threshold_tokens"] = get_auto_compact_threshold_tokens(normalized)
|
|
359
|
+
normalized["auto_compact_threshold_percentage"] = get_auto_compact_threshold_percentage(normalized)
|
|
360
|
+
return normalized
|