agentengine-sdk-python 0.8.0__py3-none-any.whl → 0.8.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/METADATA +43 -7
- agentengine_sdk_python-0.8.2.dist-info/RECORD +778 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/WHEEL +1 -1
- ksadk/a2a/__init__.py +2 -0
- ksadk/a2a/_space_client_events.py +381 -0
- ksadk/a2a/bootstrap.py +0 -2
- ksadk/a2a/card.py +6 -111
- ksadk/a2a/control_plane.py +239 -1
- ksadk/a2a/event_adapter.py +156 -64
- ksadk/a2a/executor.py +195 -172
- ksadk/a2a/routes.py +12 -5
- ksadk/a2a/server.py +1 -8
- ksadk/a2a/service_env.py +33 -0
- ksadk/a2a/space_client.py +43 -349
- ksadk/a2a_card.py +101 -0
- ksadk/a2ui/core.py +222 -53
- ksadk/agui/_agent_helpers.py +243 -0
- ksadk/agui/a2ui_projection.py +12 -5
- ksadk/agui/agent.py +474 -275
- ksadk/agui/config.py +11 -5
- ksadk/agui/routes.py +7 -15
- ksadk/api/client.py +530 -40
- ksadk/api/environment.py +27 -0
- ksadk/builders/code_builder.py +352 -53
- ksadk/builders/container_builder.py +71 -44
- ksadk/builders/framework_requirements.py +2 -1
- ksadk/builders/ks3_uploader.py +2 -2
- ksadk/builders/managed_runtime_builder.py +60 -28
- ksadk/cli/__init__.py +25 -0
- ksadk/cli/cmd_a2a.py +18 -31
- ksadk/cli/cmd_create.py +13 -26
- ksadk/cli/cmd_dashboard.py +15 -1
- ksadk/cli/cmd_deploy.py +28 -3
- ksadk/cli/cmd_eval.py +443 -0
- ksadk/cli/cmd_evalset.py +284 -0
- ksadk/cli/cmd_files.py +5 -1
- ksadk/cli/cmd_hermes.py +137 -163
- ksadk/cli/cmd_invoke.py +28 -38
- ksadk/cli/cmd_launch.py +12 -0
- ksadk/cli/cmd_managed_runtime.py +95 -0
- ksadk/cli/cmd_observe.py +85 -0
- ksadk/cli/cmd_openclaw.py +85 -479
- ksadk/cli/cmd_replay.py +28 -4
- ksadk/cli/cmd_run.py +29 -67
- ksadk/cli/cmd_studio.py +201 -0
- ksadk/cli/cmd_web.py +15 -6
- ksadk/cli/dry_run.py +2 -1
- ksadk/cli/env_options.py +83 -0
- ksadk/cli/global_options.py +3 -1
- ksadk/cli/hermes_env.py +151 -0
- ksadk/cli/invoke_payload.py +49 -0
- ksadk/cli/network_options.py +7 -5
- ksadk/cli/openclaw_env.py +458 -0
- ksadk/cli/runtime_bootstrap.py +51 -0
- ksadk/cli/ui.py +6 -0
- ksadk/cli/workflow_common.py +5 -5
- ksadk/codex/__init__.py +3 -3
- ksadk/codex/client.py +833 -49
- ksadk/codex/phase.py +1 -1
- ksadk/codex/runtime.py +720 -127
- ksadk/common/kop_client.py +232 -0
- ksadk/configs/__init__.py +1 -3
- ksadk/configs/env_registry.py +244 -45
- ksadk/configs/env_registry_pcm.py +181 -0
- ksadk/configs/env_var_spec.py +18 -0
- ksadk/configs/global_config.py +6 -1
- ksadk/configs/settings.py +5 -108
- ksadk/context_engine/__init__.py +98 -0
- ksadk/context_engine/assembler.py +176 -0
- ksadk/context_engine/baseline.py +419 -0
- ksadk/context_engine/cache_observability.py +228 -0
- ksadk/context_engine/capabilities.py +443 -0
- ksadk/context_engine/contributors.py +344 -0
- ksadk/context_engine/hosted_pipeline.py +417 -0
- ksadk/context_engine/models.py +117 -0
- ksadk/context_engine/planner.py +698 -0
- ksadk/context_engine/policies.py +319 -0
- ksadk/context_engine/projection.py +31 -0
- ksadk/context_engine/shadow_plan.py +266 -0
- ksadk/context_engine/tokenizer.py +164 -0
- ksadk/conversations/__init__.py +85 -94
- ksadk/conversations/context.py +126 -6
- ksadk/conversations/message_projection.py +292 -28
- ksadk/conversations/model_context.py +49 -3
- ksadk/conversations/runtime_compaction.py +207 -5
- ksadk/conversations/runtime_input.py +193 -3
- ksadk/conversations/runtime_invocation.py +81 -3
- ksadk/conversations/runtime_observability.py +157 -4
- ksadk/conversations/runtime_payloads.py +42 -0
- ksadk/conversations/runtime_preparation.py +280 -2
- ksadk/conversations/runtime_resume.py +71 -32
- ksadk/conversations/runtime_stream_events.py +94 -9
- ksadk/conversations/runtime_streaming.py +175 -22
- ksadk/conversations/semantic_summary.py +311 -1
- ksadk/conversations/session_lock.py +51 -0
- ksadk/deployment/env_forward.py +72 -0
- ksadk/deployment/managed_runtime.py +38 -0
- ksadk/deployment/manager.py +24 -8
- ksadk/deployment/providers/serverless.py +228 -92
- ksadk/evaluation/__init__.py +116 -0
- ksadk/evaluation/a2a_adapter.py +452 -0
- ksadk/evaluation/adapters.py +67 -0
- ksadk/evaluation/agent_eval_client.py +395 -0
- ksadk/evaluation/cloud_binding.py +80 -0
- ksadk/evaluation/cloud_converter.py +194 -0
- ksadk/evaluation/cloud_service.py +199 -0
- ksadk/evaluation/contracts.py +478 -0
- ksadk/evaluation/evalset.py +351 -0
- ksadk/evaluation/evaluators.py +627 -0
- ksadk/evaluation/evidence.py +258 -0
- ksadk/evaluation/executor.py +143 -0
- ksadk/evaluation/local_adapter.py +550 -0
- ksadk/evaluation/service_env.py +27 -0
- ksadk/evaluation/storage.py +68 -0
- ksadk/evaluation/studio_build_adapter.py +253 -0
- ksadk/evaluation/target.py +82 -0
- ksadk/events/__init__.py +13 -13
- ksadk/events/_v1_compat/__init__.py +1 -0
- ksadk/events/_v1_compat/models.py +299 -0
- ksadk/events/_v1_compat/parser.py +247 -0
- ksadk/events/_v1_compat/projection.py +753 -0
- ksadk/events/adapters/__init__.py +34 -0
- ksadk/events/adapters/_a2a_snapshot.py +622 -0
- ksadk/events/adapters/_a2a_support.py +275 -0
- ksadk/events/adapters/_codex_interactions.py +375 -0
- ksadk/events/adapters/_codex_items.py +801 -0
- ksadk/events/adapters/_codex_validators.py +311 -0
- ksadk/events/adapters/_langgraph_support.py +785 -0
- ksadk/events/adapters/a2a.py +841 -0
- ksadk/events/adapters/adk.py +503 -0
- ksadk/events/adapters/codex.py +717 -0
- ksadk/events/adapters/langgraph.py +745 -0
- ksadk/events/canonical.py +440 -0
- ksadk/events/canonical_replay.py +497 -0
- ksadk/events/canonical_store.py +468 -0
- ksadk/events/cold_recovery.py +257 -0
- ksadk/events/content.py +89 -0
- ksadk/events/identity.py +86 -0
- ksadk/events/pipeline.py +455 -0
- ksadk/events/projections.py +66 -0
- ksadk/events/reducer.py +661 -0
- ksadk/events/replay.py +3 -36
- ksadk/events/runtime_event.py +20 -256
- ksadk/events/session_event.py +324 -0
- ksadk/events/store.py +3 -316
- ksadk/events/v1_compat.py +41 -0
- ksadk/harness/__init__.py +3 -2
- ksadk/harness/app.py +114 -123
- ksadk/harness/config.py +1 -1
- ksadk/harness/runtime.py +467 -0
- ksadk/hermes_terminal.py +5 -0
- ksadk/identity/resolver.py +4 -3
- ksadk/interaction/__init__.py +28 -0
- ksadk/interaction/contracts.py +136 -0
- ksadk/interaction/ledger.py +189 -0
- ksadk/interaction/provider.py +122 -0
- ksadk/interaction/providers/__init__.py +52 -0
- ksadk/interaction/providers/adk.py +40 -0
- ksadk/interaction/providers/codex.py +94 -0
- ksadk/interaction/providers/langgraph.py +58 -0
- ksadk/kernel/__init__.py +117 -0
- ksadk/kernel/authorization.py +258 -0
- ksadk/kernel/bootstrap.py +1074 -0
- ksadk/kernel/contract_fingerprints.py +61 -0
- ksadk/kernel/contracts.py +362 -0
- ksadk/kernel/control.py +219 -0
- ksadk/kernel/errors.py +79 -0
- ksadk/kernel/ingress.py +1102 -0
- ksadk/kernel/mapping.py +111 -0
- ksadk/kernel/memory_store.py +1133 -0
- ksadk/kernel/postgres_store.py +1756 -0
- ksadk/kernel/recovery.py +452 -0
- ksadk/kernel/runtime_identity.py +103 -0
- ksadk/kernel/sql/001_agent_kernel.sql +120 -0
- ksadk/kernel/sqlite_store.py +1410 -0
- ksadk/kernel/state.py +145 -0
- ksadk/kernel/store.py +232 -0
- ksadk/kernel/worker.py +953 -0
- ksadk/knowledge_base/client.py +22 -4
- ksadk/knowledge_base/service.py +32 -5
- ksadk/managed_a2a_card.py +160 -0
- ksadk/managed_runtime.py +16 -9
- ksadk/memory/__init__.py +61 -0
- ksadk/memory/adk/backends/base_ltm_backend.py +96 -1
- ksadk/memory/adk/backends/http_ltm_backend.py +14 -5
- ksadk/memory/adk/backends/inmemory_ltm_backend.py +136 -3
- ksadk/memory/adk/backends/sdk_ltm_backend.py +394 -5
- ksadk/memory/adk/backends/sqlite_ltm_backend.py +95 -0
- ksadk/memory/adk/long_term_memory.py +3 -2
- ksadk/memory/coordinator.py +461 -0
- ksadk/memory/events.py +202 -0
- ksadk/memory/extraction.py +228 -0
- ksadk/memory/ltm_backend_factory.py +16 -3
- ksadk/memory/models.py +316 -0
- ksadk/memory/policy.py +215 -0
- ksadk/memory/provider.py +47 -0
- ksadk/memory/provider_adapter.py +159 -0
- ksadk/memory/provider_resolver.py +71 -0
- ksadk/memory/providers/__init__.py +5 -0
- ksadk/memory/providers/local_sqlite.py +490 -0
- ksadk/memory/resolved_policy.py +145 -0
- ksadk/memory/service.py +198 -8
- ksadk/memory/tool.py +4 -0
- ksadk/model_proxy/bootstrap.py +16 -9
- ksadk/model_proxy/config.py +22 -1
- ksadk/model_proxy/detect.py +202 -9
- ksadk/model_proxy/namespace.py +67 -15
- ksadk/model_proxy/server.py +168 -6
- ksadk/model_proxy/transform.py +105 -3
- ksadk/observability/__init__.py +25 -0
- ksadk/observability/session_log.py +420 -0
- ksadk/observability/trajectory.py +105 -0
- ksadk/prompts/__init__.py +71 -0
- ksadk/prompts/compiler.py +215 -0
- ksadk/prompts/models.py +82 -0
- ksadk/prompts/projection.py +89 -0
- ksadk/prompts/resolved.py +137 -0
- ksadk/prompts/sources.py +233 -0
- ksadk/runners/_langgraph_runner_streams.py +822 -0
- ksadk/runners/adk_runner.py +14 -31
- ksadk/runners/base_runner.py +44 -3
- ksadk/runners/factory.py +3 -3
- ksadk/runners/langgraph_runner.py +252 -433
- ksadk/runners/utils/__init__.py +0 -10
- ksadk/runners/utils/loader.py +16 -0
- ksadk/runtime/__init__.py +67 -41
- ksadk/runtime/_runner_adapter/__init__.py +1 -0
- ksadk/runtime/_runner_adapter/stream_mapping.py +788 -0
- ksadk/runtime/adapter.py +199 -16
- ksadk/runtime/conversation_execution.py +687 -0
- ksadk/runtime/executor.py +392 -0
- ksadk/runtime/factory.py +342 -0
- ksadk/runtime/framework_adapters.py +6 -12
- ksadk/runtime/hosted_finalizer.py +268 -0
- ksadk/runtime/launch.py +61 -0
- ksadk/runtime/preprocessing.py +49 -14
- ksadk/runtime/runner_adapter.py +330 -391
- ksadk/runtime/runner_loading.py +36 -0
- ksadk/runtime/usage.py +33 -0
- ksadk/sandbox/backends/e2b.py +36 -3
- ksadk/server/__init__.py +39 -4
- ksadk/server/app.py +18 -492
- ksadk/server/composition.py +36 -2
- ksadk/server/factory.py +210 -149
- ksadk/server/routes/common.py +15 -46
- ksadk/server/routes/control.py +13 -9
- ksadk/server/routes/kernel_ingress.py +258 -0
- ksadk/server/routes/misc.py +10 -33
- ksadk/server/routes/models.py +14 -6
- ksadk/server/routes/openai_compat.py +129 -27
- ksadk/server/routes/projection.py +84 -16
- ksadk/server/routes/run.py +347 -460
- ksadk/server/routes/sessions.py +37 -40
- ksadk/server/routes/streaming.py +52 -7
- ksadk/server/routes/workspace.py +54 -21
- ksadk/server/static/assets/{ArtifactsPanel-Cjnqt-8W.js → ArtifactsPanel-DSU1sWD_.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-BqyqZfuB.js → CodeBlock-DOH6MVcn.js} +4 -4
- ksadk/server/static/assets/{MathMessageMarkdown-BpH7jiFM.js → MathMessageMarkdown-BL8my1R2.js} +4 -4
- ksadk/server/static/assets/MathMessageMarkdown-BorAY7qD.css +1 -0
- ksadk/server/static/assets/MermaidBlock-Dz4IP-Tx.js +312 -0
- ksadk/server/static/assets/NativeTerminalPanel-DUrK0JpZ.js +1 -0
- ksadk/server/static/assets/abnfDiagram-VCTEODGH-g20pFzNV.js +1 -0
- ksadk/server/static/assets/arc-C4FzinUA.js +1 -0
- ksadk/server/static/assets/architecture-7GRP2DOG-DjKratdf.js +1 -0
- ksadk/server/static/assets/architectureDiagram-5GKGNRK7-DpIqL5h4.js +36 -0
- ksadk/server/static/assets/blockDiagram-NRAW4CY4-BjkljTNz.js +129 -0
- ksadk/server/static/assets/c4Diagram-UCG6FXSJ-Dk_ieq2X.js +38 -0
- ksadk/server/static/assets/channel-4cQHKtx1.js +1 -0
- ksadk/server/static/assets/chunk-2Q5K7J3B-DmgWkESh.js +1 -0
- ksadk/server/static/assets/{chunk-FMBD7UC4-BGhvzDYt.js → chunk-5VM5RSS4-BVHAchFb.js} +1 -1
- ksadk/server/static/assets/{chunk-ND2GUHAM-D98vPd-E.js → chunk-F27PBJKO-C-ipQzuS.js} +1 -1
- ksadk/server/static/assets/chunk-G27WJ6UU-C2EyJbIK.js +231 -0
- ksadk/server/static/assets/{chunk-4BX2VUAB-CsWIQRhc.js → chunk-JWPE2WC7-vYvVJb_M.js} +1 -1
- ksadk/server/static/assets/chunk-LCL6LL3I-BcI6ysPT.js +206 -0
- ksadk/server/static/assets/chunk-POPQ4Y6H-C030x_Z1.js +1 -0
- ksadk/server/static/assets/chunk-RHFEMEQ7-yyGpsz4n.js +168 -0
- ksadk/server/static/assets/chunk-SVP7TREG-BLTlmMU7.js +88 -0
- ksadk/server/static/assets/chunk-XXDRQBXY-C_32ArgP.js +1 -0
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DLFd9Xi0.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DLFd9Xi0.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-S5V4N54A-CX3yotHq.js → cose-bilkent-JH36ORCC-9YQYwdl0.js} +1 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-DjEM48Qp.js +1 -0
- ksadk/server/static/assets/cynefinDiagram-5FMLGOSQ-ErLF5N13.js +62 -0
- ksadk/server/static/assets/cytoscape.esm-CyCl8rPi.js +321 -0
- ksadk/server/static/assets/dagre-3AP2YEHR-DFiQF-6f.js +4 -0
- ksadk/server/static/assets/dagre-BuhGnRI1.js +1 -0
- ksadk/server/static/assets/diagram-S7CK7UJ4-Bt1v8-GC.js +30 -0
- ksadk/server/static/assets/diagram-UQ7AKVKN-DSCxJdBK.js +41 -0
- ksadk/server/static/assets/diagram-VSXAHHWV-DHfYwp_9.js +3 -0
- ksadk/server/static/assets/diagram-VX7I27RA-DdzD-4Le.js +24 -0
- ksadk/server/static/assets/diagram-Z3DM3KII-Du-nAJ9F.js +24 -0
- ksadk/server/static/assets/{dist-D82mtD2s.js → dist-8hqcx0sU.js} +1 -1
- ksadk/server/static/assets/dist-B7seoj3d.js +1 -0
- ksadk/server/static/assets/{dist-DHn6nBzr.js → dist-BE7bu-DL.js} +1 -1
- ksadk/server/static/assets/{dist-eoW6tZXA.js → dist-BVDffZ0U.js} +1 -1
- ksadk/server/static/assets/{dist-C2xjE7cO.js → dist-BX8z72IC.js} +1 -1
- ksadk/server/static/assets/{dist-CgF3fj15.js → dist-Bf2M8m3N.js} +1 -1
- ksadk/server/static/assets/{dist-Bs-jQcRX.js → dist-BjU6y-A2.js} +1 -1
- ksadk/server/static/assets/{dist-Djgl2wVZ.js → dist-BytlxIDT.js} +1 -1
- ksadk/server/static/assets/{dist-CVQRZjPu.js → dist-CSh_DE14.js} +1 -1
- ksadk/server/static/assets/{dist-6CVKuTAe.js → dist-CXYYBw3_.js} +1 -1
- ksadk/server/static/assets/{dist-DlzCRy0S.js → dist-C_wsv-Qd.js} +1 -1
- ksadk/server/static/assets/{dist-DF06ORQo.js → dist-ClxGviKw.js} +1 -1
- ksadk/server/static/assets/{dist-Cf23NY4L.js → dist-CttYUqzS.js} +1 -1
- ksadk/server/static/assets/{dist-ivOya1LD.js → dist-DNp6rLRA.js} +1 -1
- ksadk/server/static/assets/{dist-BibcG1V9.js → dist-DUX-id_F.js} +1 -1
- ksadk/server/static/assets/{dist-BUHRxvDG.js → dist-DmldrHd_.js} +1 -1
- ksadk/server/static/assets/{dist-BZ9n9AjO.js → dist-DnfXs8Vn.js} +2 -2
- ksadk/server/static/assets/{dist-DqNnNFrw.js → dist-Dq9gLD7L.js} +1 -1
- ksadk/server/static/assets/{dist-CGcp2ex8.js → dist-W-TIVntx.js} +1 -1
- ksadk/server/static/assets/{dist-Cwt7koer.js → dist-dDdADKFA.js} +1 -1
- ksadk/server/static/assets/{dist-C7-3jInC.js → dist-dydu68Fl.js} +1 -1
- ksadk/server/static/assets/{dist-C99THtIA.js → dist-ngtN0DJB.js} +1 -1
- ksadk/server/static/assets/ebnfDiagram-PWID7BFC-Da9C9NO1.js +1 -0
- ksadk/server/static/assets/erDiagram-SSCWMZ5O-EAGqqR79.js +99 -0
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-CMgMaJrC.js +1 -0
- ksadk/server/static/assets/flowDiagram-A5DVABFB-BBKL0x3P.js +1 -0
- ksadk/server/static/assets/ganttDiagram-EL5Y4UJY-DqJsKb59.js +292 -0
- ksadk/server/static/assets/gitGraph-4MIJSDKK-Dw63mrhw.js +1 -0
- ksadk/server/static/assets/gitGraphDiagram-WWUBYQGX-B6g4dtDi.js +106 -0
- ksadk/server/static/assets/index-8ipRcQ-M.js +240 -0
- ksadk/server/static/assets/index-ByFCqjlh.css +2 -0
- ksadk/server/static/assets/info-A6RAGUB7-B6iAblII.js +1 -0
- ksadk/server/static/assets/infoDiagram-RXCK75RN-Djm_nbd5.js +2 -0
- ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-DLOHGvWw.js → ishikawaDiagram-5VMMS53U-DWya9SG2.js} +6 -6
- ksadk/server/static/assets/{journeyDiagram-JHISSGLW-BIzKeejT.js → journeyDiagram-EYS64GPL-DutxhSNI.js} +6 -6
- ksadk/server/static/assets/{kanban-definition-UN3LZRKU-BWHoFSw2.js → kanban-definition-3QL26DDD-DJdOF8Fm.js} +10 -10
- ksadk/server/static/assets/katex-vFWytM5c.js +257 -0
- ksadk/server/static/assets/{linear-CvMBw9cA.js → linear-BHjG8b-J.js} +1 -1
- ksadk/server/static/assets/mermaid-parser.core-KGSy4jWT.js +166 -0
- ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-CSAQxEAe.js → mindmap-definition-FBJOCRG2-9-HC88D4.js} +29 -29
- ksadk/server/static/assets/packet-AYTQ26CC-BOYAipuq.js +1 -0
- ksadk/server/static/assets/pegDiagram-XKGWAZYB-DrEZd4fD.js +1 -0
- ksadk/server/static/assets/pie-WAS4IAKB-Ctq0Kbku.js +1 -0
- ksadk/server/static/assets/pieDiagram-E7YTZNPT-DpjqOFFp.js +39 -0
- ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-CxIR4JXI.js → quadrantDiagram-AXDQQJYC-BiNhgOXX.js} +6 -6
- ksadk/server/static/assets/radar-RG4KPBEZ-DN0-ul_0.js +1 -0
- ksadk/server/static/assets/railroad-74A4TZTK-C6cC_to0.js +1 -0
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-BimjIuRc.js +1 -0
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CvY65ABq.js +1 -0
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-D72Iq_Tv.js +1 -0
- ksadk/server/static/assets/railroadDiagram-O6MQD6OU-_Y3Ojg6G.js +1 -0
- ksadk/server/static/assets/requirementDiagram-EFPCY7ZU-DeCFdg9K.js +84 -0
- ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-DpGa6EAV.js → sankeyDiagram-P5KCCOFB-CPH75rhw.js} +7 -7
- ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-NTKNGGe5.js → sequenceDiagram-WJ2MYXX4-OEpQQdr4.js} +10 -10
- ksadk/server/static/assets/sizeCapture-X5ZJPWSS-heUErzhI.js +1 -0
- ksadk/server/static/assets/stateDiagram-HBIQ2CUA-DvA3jSMB.js +1 -0
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-BgQY03nz.js +1 -0
- ksadk/server/static/assets/swimlanes-XN3QIQJK-CR-dfN_t.js +1 -0
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-DLVw3q5Q.js +8 -0
- ksadk/server/static/assets/{timeline-definition-PNZ67QCA-jqoYs3jQ.js → timeline-definition-24CTP7MA-DAVJf1TX.js} +7 -7
- ksadk/server/static/assets/treeView-Q6P3EWNA-BMpO0wsB.js +1 -0
- ksadk/server/static/assets/treemap-WGGIJYW6-Et0aqzU3.js +1 -0
- ksadk/server/static/assets/vennDiagram-4TSXK5OY-DwM8eDkh.js +34 -0
- ksadk/server/static/assets/wardley-WFR3VGLG-CbY0mhpl.js +1 -0
- ksadk/server/static/assets/wardleyDiagram-VM6X3IG4-DZL-Zz2t.js +78 -0
- ksadk/server/static/assets/xychartDiagram-S5SC5T6Z-Dy6Yh_hu.js +7 -0
- ksadk/server/static/index.html +2 -2
- ksadk/sessions/__init__.py +26 -9
- ksadk/sessions/_local_service_sync.py +688 -0
- ksadk/sessions/_local_tables.py +21 -0
- ksadk/sessions/_postgres_schema.py +305 -0
- ksadk/sessions/_postgres_tables.py +15 -0
- ksadk/sessions/base.py +80 -1
- ksadk/sessions/in_memory.py +53 -2
- ksadk/sessions/local_service.py +63 -604
- ksadk/sessions/postgres_service.py +58 -148
- ksadk/sessions/resilient.py +35 -1
- ksadk/skills/runtime/backends/e2b.py +1 -1
- ksadk/skills/service_client.py +13 -3
- 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 +1598 -0
- ksadk/studio/api_catalog_routes.py +324 -0
- ksadk/studio/api_contracts.py +286 -0
- ksadk/studio/api_helpers.py +132 -0
- ksadk/studio/api_memory_routes.py +82 -0
- ksadk/studio/authoring.py +749 -0
- ksadk/studio/authoring_coordinator.py +1017 -0
- ksadk/studio/builder.py +397 -0
- ksadk/studio/capabilities.py +368 -0
- ksadk/studio/cloud.py +2099 -0
- ksadk/studio/codex_agent_service.py +694 -0
- ksadk/studio/codex_authoring.py +469 -0
- ksadk/studio/codex_builder.py +437 -0
- ksadk/studio/codex_manifest.py +307 -0
- ksadk/studio/codex_run.py +395 -0
- ksadk/studio/compiler.py +190 -0
- ksadk/studio/contracts.py +755 -0
- ksadk/studio/errors.py +47 -0
- ksadk/studio/event_store.py +214 -0
- ksadk/studio/framework_run.py +342 -0
- ksadk/studio/hosted_kernel.py +317 -0
- ksadk/studio/identifiers.py +33 -0
- ksadk/studio/manifest_resolver.py +131 -0
- ksadk/studio/mcp_runtime.py +229 -0
- ksadk/studio/model_client.py +629 -0
- ksadk/studio/model_profile_service.py +214 -0
- ksadk/studio/operations.py +275 -0
- ksadk/studio/otel_trace.py +1060 -0
- ksadk/studio/pagination.py +182 -0
- ksadk/studio/pcm_memory.py +85 -0
- ksadk/studio/python_tool_inspection.py +183 -0
- ksadk/studio/repository.py +327 -0
- ksadk/studio/resource_catalog.py +1260 -0
- ksadk/studio/run_service.py +1133 -0
- ksadk/studio/runtime_catalog.py +74 -0
- ksadk/studio/runtime_source.py +365 -0
- ksadk/studio/service.py +2249 -0
- ksadk/studio/shared_web.py +1004 -0
- ksadk/studio/skill_discovery.py +628 -0
- ksadk/studio/static/assets/PrismRenderer-IYN-ffww.js +3 -0
- ksadk/studio/static/assets/index-BLpcdrgW.css +1 -0
- ksadk/studio/static/assets/index-CYekR2Xv.js +260 -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 +722 -0
- ksadk/studio/validator.py +265 -0
- ksadk/studio/workspace.py +135 -0
- ksadk/tools/gateway.py +9 -0
- ksadk/toolsets/__init__.py +27 -1
- ksadk/toolsets/a2a.py +426 -0
- ksadk/tracing/__init__.py +19 -21
- ksadk/tracing/setup.py +317 -403
- ksadk/tracing/span_utils.py +0 -44
- ksadk/version.py +1 -1
- ksadk_runtime_common/memory_backend/registry.py +56 -56
- ksadk_runtime_common/schemas/runtime_event_v1.json +37 -0
- ksadk_runtime_common/schemas/runtime_event_v2.json +271 -0
- ksadk_runtime_common/workspace_files/router.py +8 -2
- agentengine_sdk_python-0.8.0.dist-info/RECORD +0 -578
- ksadk/a2a/card_builder.py +0 -64
- ksadk/a2a/client.py +0 -309
- ksadk/events/parser.py +0 -191
- ksadk/harness/runner.py +0 -211
- ksadk/runners/codex_runner.py +0 -132
- ksadk/runners/utils/langfuse.py +0 -230
- ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +0 -1
- ksadk/server/static/assets/MermaidBlock-DWuxETaJ.js +0 -303
- ksadk/server/static/assets/NativeTerminalPanel-MDTopWMO.js +0 -1
- ksadk/server/static/assets/arc-CFKwSk_B.js +0 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-CynqOWjZ.js +0 -1
- ksadk/server/static/assets/architectureDiagram-3BPJPVTR-Dej8jX8c.js +0 -36
- ksadk/server/static/assets/blockDiagram-GPEHLZMM-1F64jqvy.js +0 -132
- ksadk/server/static/assets/c4Diagram-AAUBKEIU-9q7AUAKb.js +0 -10
- ksadk/server/static/assets/channel-iUGv2N24.js +0 -1
- ksadk/server/static/assets/chunk-2J33WTMH-6qgwJm7Q.js +0 -1
- ksadk/server/static/assets/chunk-55IACEB6-BK8paA20.js +0 -1
- ksadk/server/static/assets/chunk-727SXJPM-B-JEhy7h.js +0 -206
- ksadk/server/static/assets/chunk-AQP2D5EJ-DYBvMHAa.js +0 -231
- ksadk/server/static/assets/chunk-QZHKN3VN-YQIEXeF6.js +0 -1
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-CDAUuoXK.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-CDAUuoXK.js +0 -1
- ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +0 -321
- ksadk/server/static/assets/dagre-BM42HDAG-C7TguAWo.js +0 -4
- ksadk/server/static/assets/dagre-Bx709z4p.js +0 -1
- ksadk/server/static/assets/diagram-2AECGRRQ-Dd17_kws.js +0 -43
- ksadk/server/static/assets/diagram-5GNKFQAL-DVIClIil.js +0 -10
- ksadk/server/static/assets/diagram-KO2AKTUF-Df_3gYQa.js +0 -3
- ksadk/server/static/assets/diagram-LMA3HP47-BhLk6ZtA.js +0 -24
- ksadk/server/static/assets/diagram-OG6HWLK6-D4GNGvuu.js +0 -24
- ksadk/server/static/assets/dist-DyvYLMW9.js +0 -1
- ksadk/server/static/assets/erDiagram-TEJ5UH35-CnfRcY2M.js +0 -85
- ksadk/server/static/assets/eventmodeling-FCH6USID-ChYO-ijM.js +0 -1
- ksadk/server/static/assets/flowDiagram-I6XJVG4X-DGaJjGNJ.js +0 -162
- ksadk/server/static/assets/ganttDiagram-6RSMTGT7-DpCoB2g9.js +0 -292
- ksadk/server/static/assets/gitGraph-WXDBUCRP-BN_0Fk-j.js +0 -1
- ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-9IKVFBVT.js +0 -106
- ksadk/server/static/assets/graphlib-B8gBHxth.js +0 -1
- ksadk/server/static/assets/index-QSwCHuB8.js +0 -177
- ksadk/server/static/assets/index-jOPmTOZH.css +0 -2
- ksadk/server/static/assets/info-J43DQDTF-Cp6o3vId.js +0 -1
- ksadk/server/static/assets/infoDiagram-5YYISTIA-CYIIsb8y.js +0 -2
- ksadk/server/static/assets/katex-DATssjp1.js +0 -265
- ksadk/server/static/assets/mermaid-parser.core-mGAcEwcq.js +0 -161
- ksadk/server/static/assets/packet-YPE3B663-wQzct3cT.js +0 -1
- ksadk/server/static/assets/pie-LRSECV5Y-BgTQiv-9.js +0 -1
- ksadk/server/static/assets/pieDiagram-4H26LBE5-By-ra07M.js +0 -30
- ksadk/server/static/assets/radar-GUYGQ44K-BIq5fXsn.js +0 -1
- ksadk/server/static/assets/requirementDiagram-4Y6WPE33-DpW90iu3.js +0 -84
- ksadk/server/static/assets/stateDiagram-AJRCARHV-DGpd9yFG.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-B3o579IQ.js +0 -1
- ksadk/server/static/assets/treeView-BLDUP644-Dqi-E0EM.js +0 -1
- ksadk/server/static/assets/treemap-LRROVOQU-ClQP9CJ9.js +0 -1
- ksadk/server/static/assets/vennDiagram-CIIHVFJN-l3Z7-wbP.js +0 -34
- ksadk/server/static/assets/wardley-L42UT6IY-8XLvnNIs.js +0 -1
- ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-BR54GPmr.js +0 -78
- ksadk/server/static/assets/xychartDiagram-2RQKCTM6-SkiH8GsK.js +0 -7
- ksadk/tracing/exporters/langfuse_exporter.py +0 -460
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
"""Codex adapter 的常量、状态 dataclass 与内容构造辅助(纯移动自 codex,行为不变)。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from functools import lru_cache
|
|
8
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
9
|
+
from typing import Any, Callable, Literal, cast
|
|
10
|
+
|
|
11
|
+
from pydantic import JsonValue
|
|
12
|
+
|
|
13
|
+
from ksadk.events.adapters._codex_validators import (
|
|
14
|
+
_approval_decision,
|
|
15
|
+
_fail,
|
|
16
|
+
_json_value,
|
|
17
|
+
_mapping,
|
|
18
|
+
_nonnegative_int,
|
|
19
|
+
_optional_int,
|
|
20
|
+
_required_string,
|
|
21
|
+
_required_text,
|
|
22
|
+
_string_sequence,
|
|
23
|
+
_validated_user_input_answers,
|
|
24
|
+
)
|
|
25
|
+
from ksadk.events.canonical import (
|
|
26
|
+
ApprovalResponse,
|
|
27
|
+
EventPhase,
|
|
28
|
+
ItemKind,
|
|
29
|
+
SourceRef,
|
|
30
|
+
StructuredInputRequest,
|
|
31
|
+
)
|
|
32
|
+
from ksadk.events.content import (
|
|
33
|
+
ArtifactContent,
|
|
34
|
+
ContentSnapshot,
|
|
35
|
+
ContentValue,
|
|
36
|
+
DataContent,
|
|
37
|
+
TextContent,
|
|
38
|
+
ToolCallContent,
|
|
39
|
+
ToolResultContent,
|
|
40
|
+
)
|
|
41
|
+
from ksadk.events.identity import stable_event_id, stable_item_id, stable_part_id, stable_scope_id
|
|
42
|
+
|
|
43
|
+
_CODEX_0_147_0_NOTIFICATION_METHODS = frozenset("""
|
|
44
|
+
account/login/completed account/rateLimits/updated account/updated app/list/updated
|
|
45
|
+
command/exec/outputDelta configWarning deprecationNotice error
|
|
46
|
+
externalAgentConfig/import/completed externalAgentConfig/import/progress fs/changed
|
|
47
|
+
fuzzyFileSearch/sessionCompleted fuzzyFileSearch/sessionUpdated guardianWarning
|
|
48
|
+
hook/completed hook/started item/agentMessage/delta item/autoApprovalReview/completed
|
|
49
|
+
item/autoApprovalReview/started item/commandExecution/outputDelta
|
|
50
|
+
item/commandExecution/terminalInteraction item/completed item/fileChange/outputDelta
|
|
51
|
+
item/fileChange/patchUpdated item/mcpToolCall/progress item/plan/delta
|
|
52
|
+
item/reasoning/summaryPartAdded item/reasoning/summaryTextDelta item/reasoning/textDelta
|
|
53
|
+
item/started mcpServer/oauthLogin/completed mcpServer/startupStatus/updated
|
|
54
|
+
model/rerouted model/safetyBuffering/updated model/verification process/exited
|
|
55
|
+
process/outputDelta remoteControl/status/changed serverRequest/resolved skills/changed
|
|
56
|
+
thread/archived thread/closed thread/compacted thread/deleted thread/goal/cleared
|
|
57
|
+
thread/environment/connected thread/environment/disconnected
|
|
58
|
+
thread/goal/updated thread/name/updated thread/realtime/closed thread/realtime/error
|
|
59
|
+
thread/realtime/itemAdded thread/realtime/outputAudio/delta thread/realtime/sdp
|
|
60
|
+
thread/realtime/started thread/realtime/transcript/delta thread/realtime/transcript/done
|
|
61
|
+
thread/settings/updated thread/started thread/status/changed thread/tokenUsage/updated
|
|
62
|
+
thread/unarchived turn/completed turn/diff/updated turn/moderationMetadata
|
|
63
|
+
turn/plan/updated turn/started warning windows/worldWritableWarning
|
|
64
|
+
windowsSandbox/setupCompleted
|
|
65
|
+
""".split())
|
|
66
|
+
|
|
67
|
+
_CODEX_0_144_4_DATA_ITEM_KINDS = frozenset("""
|
|
68
|
+
userMessage hookPrompt subAgentActivity imageView sleep enteredReviewMode
|
|
69
|
+
exitedReviewMode contextCompaction
|
|
70
|
+
""".split())
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# Methods that carry item-lifecycle semantics and need thread/turn scoping.
|
|
74
|
+
_ITEM_METHODS = frozenset("""
|
|
75
|
+
error item/started item/completed item/agentMessage/delta item/reasoning/textDelta
|
|
76
|
+
item/reasoning/summaryPartAdded item/reasoning/summaryTextDelta
|
|
77
|
+
item/commandExecution/outputDelta item/mcpToolCall/progress
|
|
78
|
+
item/fileChange/patchUpdated item/fileChange/outputDelta item/plan/delta
|
|
79
|
+
""".split())
|
|
80
|
+
_INTERACTION_METHODS = frozenset("""
|
|
81
|
+
item/commandExecution/requestApproval item/fileChange/requestApproval
|
|
82
|
+
item/permissions/requestApproval item/tool/call item/tool/requestUserInput
|
|
83
|
+
mcpServer/elicitation/request
|
|
84
|
+
""".split())
|
|
85
|
+
_CONTROL_INTERACTION_METHODS = frozenset(
|
|
86
|
+
{"account/chatgptAuthTokens/refresh", "attestation/generate"}
|
|
87
|
+
)
|
|
88
|
+
_APPROVAL_KINDS = {
|
|
89
|
+
"item/commandExecution/requestApproval": "command_execution",
|
|
90
|
+
"item/fileChange/requestApproval": "file_change",
|
|
91
|
+
"item/permissions/requestApproval": "permissions",
|
|
92
|
+
"item/tool/call": "dynamic_tool_call",
|
|
93
|
+
}
|
|
94
|
+
# native item kind -> canonical (item_kind, default phase); agentMessage is validated separately.
|
|
95
|
+
_ITEM_KIND_PHASES: dict[str, tuple[ItemKind, EventPhase]] = {
|
|
96
|
+
"agentMessage": ("message", "final_answer"),
|
|
97
|
+
"reasoning": ("reasoning", "commentary"),
|
|
98
|
+
"commandExecution": ("tool_call", "commentary"),
|
|
99
|
+
"mcpToolCall": ("tool_call", "commentary"),
|
|
100
|
+
"dynamicToolCall": ("tool_call", "commentary"),
|
|
101
|
+
"collabAgentToolCall": ("tool_call", "commentary"),
|
|
102
|
+
"webSearch": ("tool_call", "commentary"),
|
|
103
|
+
"fileChange": ("data", "commentary"),
|
|
104
|
+
"plan": ("data", "commentary"),
|
|
105
|
+
"imageGeneration": ("artifact", "commentary"),
|
|
106
|
+
**{kind: ("data", "commentary") for kind in _CODEX_0_144_4_DATA_ITEM_KINDS},
|
|
107
|
+
}
|
|
108
|
+
# native item kind -> statuses that terminate the item as failed.
|
|
109
|
+
_ITEM_FAIL_STATUSES = {
|
|
110
|
+
"commandExecution": frozenset({"failed", "declined"}),
|
|
111
|
+
"mcpToolCall": frozenset({"failed"}),
|
|
112
|
+
"fileChange": frozenset({"failed", "declined"}),
|
|
113
|
+
"dynamicToolCall": frozenset({"failed"}),
|
|
114
|
+
"collabAgentToolCall": frozenset({"failed"}),
|
|
115
|
+
}
|
|
116
|
+
_FAILURE_CODE_KINDS = {
|
|
117
|
+
"commandExecution": "command",
|
|
118
|
+
"mcpToolCall": "mcp_tool",
|
|
119
|
+
"fileChange": "file_change",
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@dataclass
|
|
124
|
+
class CodexAdapterContext:
|
|
125
|
+
"""Runtime identity and deterministic pre-store placeholder ordering."""
|
|
126
|
+
|
|
127
|
+
run_id: str
|
|
128
|
+
initial_seq: int = 0
|
|
129
|
+
_next_seq: int = field(init=False, repr=False)
|
|
130
|
+
|
|
131
|
+
def __post_init__(self) -> None:
|
|
132
|
+
self.run_id = _required_string(self.run_id, "runtime run_id")
|
|
133
|
+
if self.initial_seq < 0:
|
|
134
|
+
raise ValueError("Codex initial_seq must be non-negative")
|
|
135
|
+
self._next_seq = self.initial_seq
|
|
136
|
+
|
|
137
|
+
def allocate_placeholder_seq(self) -> int:
|
|
138
|
+
value = self._next_seq
|
|
139
|
+
self._next_seq += 1
|
|
140
|
+
return value
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@dataclass
|
|
144
|
+
class _ItemState:
|
|
145
|
+
scope_id: str
|
|
146
|
+
thread_id: str
|
|
147
|
+
turn_id: str
|
|
148
|
+
native_item_id: str
|
|
149
|
+
native_item_kind: str
|
|
150
|
+
item_id: str
|
|
151
|
+
item_kind: ItemKind
|
|
152
|
+
phase: EventPhase
|
|
153
|
+
part_ids: dict[str, str] = field(default_factory=dict)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@dataclass(frozen=True)
|
|
157
|
+
class _InteractionState:
|
|
158
|
+
request_id: str
|
|
159
|
+
interaction_id: str
|
|
160
|
+
interaction_kind: Literal["approval", "structured_input"]
|
|
161
|
+
scope_id: str
|
|
162
|
+
thread_id: str
|
|
163
|
+
turn_id: str
|
|
164
|
+
native_item_id: str
|
|
165
|
+
method: str
|
|
166
|
+
interrupts_run: bool
|
|
167
|
+
question_ids: frozenset[str] = frozenset()
|
|
168
|
+
secret_question_ids: frozenset[str] = frozenset()
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@dataclass(frozen=True)
|
|
172
|
+
class _ReplayRecord:
|
|
173
|
+
payload_digest: str
|
|
174
|
+
event_ids: tuple[str, ...]
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _elicitation_request(params: Mapping[str, Any]) -> StructuredInputRequest:
|
|
178
|
+
mode = _required_string(params.get("mode"), "params.mode")
|
|
179
|
+
prompt = _required_text(params.get("message"), "params.message")
|
|
180
|
+
if mode in {"form", "openai/form"}:
|
|
181
|
+
schema_value = _mapping(params.get("requestedSchema"), "params.requestedSchema")
|
|
182
|
+
schema = cast(dict[str, JsonValue], _json_value(schema_value))
|
|
183
|
+
elif mode == "url":
|
|
184
|
+
schema = {
|
|
185
|
+
"type": "object",
|
|
186
|
+
"x-codex-elicitation-url": _required_text(params.get("url"), "params.url"),
|
|
187
|
+
"x-codex-elicitation-id": _required_text(
|
|
188
|
+
params.get("elicitationId"), "params.elicitationId"
|
|
189
|
+
),
|
|
190
|
+
}
|
|
191
|
+
else:
|
|
192
|
+
_fail(
|
|
193
|
+
"invalid_interaction_request",
|
|
194
|
+
"params.mode",
|
|
195
|
+
f"Unsupported MCP elicitation mode: {mode}",
|
|
196
|
+
)
|
|
197
|
+
return StructuredInputRequest(prompt=prompt, schema=schema)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _control_refresh_request(params: Mapping[str, Any]) -> StructuredInputRequest:
|
|
201
|
+
reason = _required_string(params.get("reason"), "params.reason")
|
|
202
|
+
if reason != "unauthorized":
|
|
203
|
+
_fail(
|
|
204
|
+
"invalid_interaction_request",
|
|
205
|
+
"params.reason",
|
|
206
|
+
f"Unsupported ChatGPT token refresh reason: {reason}",
|
|
207
|
+
)
|
|
208
|
+
previous_account_id = params.get("previousAccountId")
|
|
209
|
+
if previous_account_id is not None:
|
|
210
|
+
_required_string(previous_account_id, "params.previousAccountId")
|
|
211
|
+
return StructuredInputRequest(
|
|
212
|
+
prompt="Refresh ChatGPT authentication tokens",
|
|
213
|
+
schema={
|
|
214
|
+
"type": "object",
|
|
215
|
+
"properties": {
|
|
216
|
+
"accessToken": {"type": "string"},
|
|
217
|
+
"chatgptAccountId": {"type": "string"},
|
|
218
|
+
"chatgptPlanType": {"type": ["string", "null"]},
|
|
219
|
+
},
|
|
220
|
+
"required": ["accessToken", "chatgptAccountId"],
|
|
221
|
+
"x-codex-request": _json_value(params),
|
|
222
|
+
},
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _control_attestation_request(params: Mapping[str, Any]) -> StructuredInputRequest:
|
|
227
|
+
if params:
|
|
228
|
+
_fail(
|
|
229
|
+
"invalid_interaction_request",
|
|
230
|
+
"params",
|
|
231
|
+
"Codex attestation/generate params must be empty",
|
|
232
|
+
)
|
|
233
|
+
return StructuredInputRequest(
|
|
234
|
+
prompt="Generate an upstream attestation token",
|
|
235
|
+
schema={
|
|
236
|
+
"type": "object",
|
|
237
|
+
"properties": {"token": {"type": "string"}},
|
|
238
|
+
"required": ["token"],
|
|
239
|
+
},
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
_CONTROL_REQUEST_BUILDERS: dict[str, Callable[[Mapping[str, Any]], StructuredInputRequest]] = {
|
|
244
|
+
"account/chatgptAuthTokens/refresh": _control_refresh_request,
|
|
245
|
+
"attestation/generate": _control_attestation_request,
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _approval_response(method: str, result: Mapping[str, Any]) -> ApprovalResponse:
|
|
250
|
+
if method in {"item/commandExecution/requestApproval", "item/fileChange/requestApproval"}:
|
|
251
|
+
if result.get("decision") is None:
|
|
252
|
+
_fail(
|
|
253
|
+
"missing_native_identity",
|
|
254
|
+
"result.decision",
|
|
255
|
+
"Codex approval result.decision is required",
|
|
256
|
+
)
|
|
257
|
+
return ApprovalResponse(
|
|
258
|
+
decision=_approval_decision(result.get("decision")),
|
|
259
|
+
data=_json_value(result),
|
|
260
|
+
)
|
|
261
|
+
if method == "item/permissions/requestApproval":
|
|
262
|
+
return ApprovalResponse(decision="approved", data=_json_value(result))
|
|
263
|
+
# item/tool/call; state creation exhaustively validates the method.
|
|
264
|
+
success = result.get("success")
|
|
265
|
+
if not isinstance(success, bool):
|
|
266
|
+
_fail(
|
|
267
|
+
"invalid_interaction_response",
|
|
268
|
+
"result.success",
|
|
269
|
+
"Codex dynamic tool result.success must be a boolean",
|
|
270
|
+
)
|
|
271
|
+
return ApprovalResponse(
|
|
272
|
+
decision="approved" if success else "rejected", data=_json_value(result)
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _structured_response_data(
|
|
277
|
+
state: _InteractionState, result: Mapping[str, Any]
|
|
278
|
+
) -> dict[str, JsonValue]:
|
|
279
|
+
if state.method == "account/chatgptAuthTokens/refresh":
|
|
280
|
+
_required_string(result.get("accessToken"), "result.accessToken")
|
|
281
|
+
account_id = _required_string(result.get("chatgptAccountId"), "result.chatgptAccountId")
|
|
282
|
+
plan_type = result.get("chatgptPlanType")
|
|
283
|
+
if plan_type is not None:
|
|
284
|
+
_required_string(plan_type, "result.chatgptPlanType")
|
|
285
|
+
return {
|
|
286
|
+
"accessTokenPresent": True,
|
|
287
|
+
"chatgptAccountId": account_id,
|
|
288
|
+
"chatgptPlanType": cast(JsonValue, plan_type),
|
|
289
|
+
}
|
|
290
|
+
if state.method == "attestation/generate":
|
|
291
|
+
_required_string(result.get("token"), "result.token")
|
|
292
|
+
return {"tokenPresent": True}
|
|
293
|
+
if state.method == "item/tool/requestUserInput":
|
|
294
|
+
return _validated_user_input_answers(result, state.question_ids, state.secret_question_ids)
|
|
295
|
+
return cast(dict[str, JsonValue], _json_value(result))
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def _item_state(
|
|
299
|
+
scope_id: str,
|
|
300
|
+
thread_id: str,
|
|
301
|
+
turn_id: str,
|
|
302
|
+
native_item_id: str,
|
|
303
|
+
native_kind: str,
|
|
304
|
+
item: Mapping[str, Any],
|
|
305
|
+
) -> _ItemState:
|
|
306
|
+
item_id = stable_item_id("codex", scope_id, native_kind, native_item_id)
|
|
307
|
+
rule = _ITEM_KIND_PHASES.get(native_kind)
|
|
308
|
+
item_kind: ItemKind
|
|
309
|
+
phase: EventPhase
|
|
310
|
+
if native_kind == "agentMessage":
|
|
311
|
+
item_kind, phase = "message", _agent_message_phase(item.get("phase"))
|
|
312
|
+
elif rule is not None:
|
|
313
|
+
item_kind, phase = rule
|
|
314
|
+
else:
|
|
315
|
+
_fail(
|
|
316
|
+
"unsupported_item_kind",
|
|
317
|
+
"params.item.type",
|
|
318
|
+
f"Unsupported Codex item type: {native_kind}",
|
|
319
|
+
)
|
|
320
|
+
return _ItemState(
|
|
321
|
+
scope_id=scope_id,
|
|
322
|
+
thread_id=thread_id,
|
|
323
|
+
turn_id=turn_id,
|
|
324
|
+
native_item_id=native_item_id,
|
|
325
|
+
native_item_kind=native_kind,
|
|
326
|
+
item_id=item_id,
|
|
327
|
+
item_kind=item_kind,
|
|
328
|
+
phase=phase,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def _agent_message_phase(value: Any) -> EventPhase:
|
|
333
|
+
if value in {None, "final_answer"}:
|
|
334
|
+
return "final_answer"
|
|
335
|
+
if value != "commentary":
|
|
336
|
+
_fail("invalid_item_phase", "params.item.phase", f"Unsupported Codex phase: {value}")
|
|
337
|
+
return "commentary"
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _part_id(state: _ItemState, native_part_kind: str, native_part_id: str) -> str:
|
|
341
|
+
lane = f"{native_part_kind}:{native_part_id}"
|
|
342
|
+
part_id = state.part_ids.get(lane)
|
|
343
|
+
if part_id is None:
|
|
344
|
+
part_id = stable_part_id("codex", state.item_id, native_part_kind, native_part_id)
|
|
345
|
+
state.part_ids[lane] = part_id
|
|
346
|
+
return part_id
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
# --- item content builders (identity translation only) -----------------------
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def _text_part(state: _ItemState, lane: str, text: str) -> TextContent:
|
|
353
|
+
return TextContent(part_id=_part_id(state, lane, "primary"), text=text)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def _reasoning_parts(state: _ItemState, item: Mapping[str, Any]) -> tuple[TextContent, ...]:
|
|
357
|
+
summary = _string_sequence(item.get("summary"), "params.item.summary")
|
|
358
|
+
content = _string_sequence(item.get("content"), "params.item.content")
|
|
359
|
+
return tuple(
|
|
360
|
+
TextContent(part_id=_part_id(state, "reasoning_summary", str(index)), text=text)
|
|
361
|
+
for index, text in enumerate(summary)
|
|
362
|
+
) + tuple(
|
|
363
|
+
TextContent(part_id=_part_id(state, "reasoning_content", str(index)), text=text)
|
|
364
|
+
for index, text in enumerate(content)
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def _command_call(state: _ItemState, item: Mapping[str, Any]) -> ToolCallContent:
|
|
369
|
+
return ToolCallContent(
|
|
370
|
+
part_id=_part_id(state, "command_call", "primary"),
|
|
371
|
+
call_id=state.native_item_id,
|
|
372
|
+
name="codex.command",
|
|
373
|
+
arguments={
|
|
374
|
+
"command": _required_text(item.get("command"), "params.item.command"),
|
|
375
|
+
"cwd": _required_text(item.get("cwd"), "params.item.cwd"),
|
|
376
|
+
"commandActions": _json_value(item.get("commandActions")),
|
|
377
|
+
},
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def _terminal_status(item: Mapping[str, Any], allowed: set[str], label: str) -> str:
|
|
382
|
+
status = _required_string(item.get("status"), "params.item.status")
|
|
383
|
+
if status not in allowed:
|
|
384
|
+
_fail(
|
|
385
|
+
"invalid_item_snapshot",
|
|
386
|
+
"params.item.status",
|
|
387
|
+
f"{label} completed with non-terminal status: {status}",
|
|
388
|
+
)
|
|
389
|
+
return status
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def _command_result(state: _ItemState, item: Mapping[str, Any]) -> ToolResultContent:
|
|
393
|
+
status = _terminal_status(item, {"completed", "failed", "declined"}, "Command")
|
|
394
|
+
exit_code = item.get("exitCode")
|
|
395
|
+
if exit_code is not None and not isinstance(exit_code, int):
|
|
396
|
+
_fail("invalid_item_snapshot", "params.item.exitCode", "Codex exitCode must be an integer")
|
|
397
|
+
return ToolResultContent(
|
|
398
|
+
part_id=_part_id(state, "command_result", "primary"),
|
|
399
|
+
call_id=state.native_item_id,
|
|
400
|
+
result={
|
|
401
|
+
"status": status,
|
|
402
|
+
"exit_code": exit_code,
|
|
403
|
+
"duration_ms": _optional_int(item.get("durationMs"), "params.item.durationMs"),
|
|
404
|
+
"output": _required_text(
|
|
405
|
+
item.get("aggregatedOutput") or "", "params.item.aggregatedOutput"
|
|
406
|
+
),
|
|
407
|
+
"process_id": item.get("processId"),
|
|
408
|
+
"source": item.get("source"),
|
|
409
|
+
},
|
|
410
|
+
is_error=status in {"failed", "declined"}
|
|
411
|
+
or (isinstance(exit_code, int) and exit_code != 0),
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def _mcp_call(state: _ItemState, item: Mapping[str, Any]) -> ToolCallContent:
|
|
416
|
+
server = _required_string(item.get("server"), "params.item.server")
|
|
417
|
+
tool = _required_string(item.get("tool"), "params.item.tool")
|
|
418
|
+
return ToolCallContent(
|
|
419
|
+
part_id=_part_id(state, "mcp_call", "primary"),
|
|
420
|
+
call_id=state.native_item_id,
|
|
421
|
+
name=f"mcp.{server}.{tool}",
|
|
422
|
+
arguments=_json_value(item.get("arguments")),
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def _mcp_result(state: _ItemState, item: Mapping[str, Any]) -> ToolResultContent:
|
|
427
|
+
status = _terminal_status(item, {"completed", "failed"}, "MCP call")
|
|
428
|
+
result = _json_value(item.get("result"))
|
|
429
|
+
error = _json_value(item.get("error"))
|
|
430
|
+
result_value: dict[str, JsonValue] = {"status": status}
|
|
431
|
+
if isinstance(result, dict):
|
|
432
|
+
result_value.update(result)
|
|
433
|
+
elif result is not None:
|
|
434
|
+
result_value["result"] = result
|
|
435
|
+
result_value["duration_ms"] = _optional_int(item.get("durationMs"), "params.item.durationMs")
|
|
436
|
+
if error is not None:
|
|
437
|
+
result_value["error"] = error
|
|
438
|
+
return ToolResultContent(
|
|
439
|
+
part_id=_part_id(state, "mcp_result", "primary"),
|
|
440
|
+
call_id=state.native_item_id,
|
|
441
|
+
result=result_value,
|
|
442
|
+
is_error=status == "failed",
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
def _file_change(state: _ItemState, item: Mapping[str, Any]) -> DataContent:
|
|
447
|
+
changes = _json_value(item.get("changes"))
|
|
448
|
+
if not isinstance(changes, list):
|
|
449
|
+
_fail("invalid_item_snapshot", "params.item.changes", "Codex file changes must be an array")
|
|
450
|
+
return DataContent(
|
|
451
|
+
part_id=_part_id(state, "file_changes", "primary"),
|
|
452
|
+
data={
|
|
453
|
+
"changes": changes,
|
|
454
|
+
"status": _required_string(item.get("status"), "params.item.status"),
|
|
455
|
+
},
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def _generic_item_data(state: _ItemState, item: Mapping[str, Any]) -> DataContent:
|
|
460
|
+
return DataContent(part_id=_part_id(state, "native_item", "primary"), data=_json_value(item))
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def _additional_tool_call(state: _ItemState, item: Mapping[str, Any]) -> ToolCallContent:
|
|
464
|
+
kind = state.native_item_kind
|
|
465
|
+
if kind == "dynamicToolCall":
|
|
466
|
+
name = _required_string(item.get("tool"), "params.item.tool")
|
|
467
|
+
arguments: JsonValue = {
|
|
468
|
+
"arguments": _json_value(item.get("arguments")),
|
|
469
|
+
"namespace": _json_value(item.get("namespace")),
|
|
470
|
+
}
|
|
471
|
+
elif kind == "collabAgentToolCall":
|
|
472
|
+
name = f"codex.collab.{_required_string(item.get('tool'), 'params.item.tool')}"
|
|
473
|
+
arguments = cast(
|
|
474
|
+
JsonValue,
|
|
475
|
+
{
|
|
476
|
+
"senderThreadId": _json_value(item.get("senderThreadId")),
|
|
477
|
+
"receiverThreadIds": _json_value(item.get("receiverThreadIds")),
|
|
478
|
+
"prompt": _json_value(item.get("prompt")),
|
|
479
|
+
"model": _json_value(item.get("model")),
|
|
480
|
+
"reasoningEffort": _json_value(item.get("reasoningEffort")),
|
|
481
|
+
},
|
|
482
|
+
)
|
|
483
|
+
else: # webSearch; caller exhaustively validates native kind
|
|
484
|
+
name = "codex.web_search"
|
|
485
|
+
arguments = {
|
|
486
|
+
"query": _required_text(item.get("query"), "params.item.query"),
|
|
487
|
+
"action": _json_value(item.get("action")),
|
|
488
|
+
}
|
|
489
|
+
return ToolCallContent(
|
|
490
|
+
part_id=_part_id(state, "tool_call", "primary"),
|
|
491
|
+
call_id=state.native_item_id,
|
|
492
|
+
name=name,
|
|
493
|
+
arguments=arguments,
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def _additional_tool_result(state: _ItemState, item: Mapping[str, Any]) -> ToolResultContent:
|
|
498
|
+
kind = state.native_item_kind
|
|
499
|
+
if kind in {"dynamicToolCall", "collabAgentToolCall"}:
|
|
500
|
+
label = "Dynamic" if kind == "dynamicToolCall" else "Collab"
|
|
501
|
+
status = _terminal_status(item, {"completed", "failed"}, label + " tool")
|
|
502
|
+
if kind == "dynamicToolCall":
|
|
503
|
+
result: JsonValue = {
|
|
504
|
+
"status": status,
|
|
505
|
+
"success": _json_value(item.get("success")),
|
|
506
|
+
"contentItems": _json_value(item.get("contentItems")),
|
|
507
|
+
"durationMs": _json_value(item.get("durationMs")),
|
|
508
|
+
}
|
|
509
|
+
is_error = status == "failed" or item.get("success") is False
|
|
510
|
+
else:
|
|
511
|
+
result = {"status": status, "agentsStates": _json_value(item.get("agentsStates"))}
|
|
512
|
+
is_error = status == "failed"
|
|
513
|
+
else: # webSearch
|
|
514
|
+
result = {"action": _json_value(item.get("action"))}
|
|
515
|
+
is_error = False
|
|
516
|
+
return ToolResultContent(
|
|
517
|
+
part_id=_part_id(state, "tool_result", "primary"),
|
|
518
|
+
call_id=state.native_item_id,
|
|
519
|
+
result=result,
|
|
520
|
+
is_error=is_error,
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
def _image_artifact(state: _ItemState, item: Mapping[str, Any]) -> ArtifactContent:
|
|
525
|
+
result = _required_text(item.get("result"), "params.item.result")
|
|
526
|
+
saved_path = item.get("savedPath")
|
|
527
|
+
if saved_path is not None and not isinstance(saved_path, str):
|
|
528
|
+
_fail(
|
|
529
|
+
"invalid_item_snapshot", "params.item.savedPath", "Codex image savedPath must be text"
|
|
530
|
+
)
|
|
531
|
+
return ArtifactContent(
|
|
532
|
+
part_id=_part_id(state, "image", "primary"),
|
|
533
|
+
artifact_id=state.native_item_id,
|
|
534
|
+
name=(saved_path.rsplit("/", 1)[-1] if saved_path else state.native_item_id),
|
|
535
|
+
uri=result or saved_path,
|
|
536
|
+
data={
|
|
537
|
+
"status": _required_string(item.get("status"), "params.item.status"),
|
|
538
|
+
"revisedPrompt": _json_value(item.get("revisedPrompt")),
|
|
539
|
+
"result": result,
|
|
540
|
+
"savedPath": _json_value(saved_path),
|
|
541
|
+
},
|
|
542
|
+
)
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
# A part builder returns one ContentValue, or a tuple of them (reasoning lists).
|
|
546
|
+
_PART_BUILDER = Callable[[_ItemState, Mapping[str, Any]], Any]
|
|
547
|
+
# native item kind -> (initial part builders, completed part builders)
|
|
548
|
+
_ITEM_SNAPSHOT_BUILDERS: dict[str, tuple[tuple[_PART_BUILDER, ...], tuple[_PART_BUILDER, ...]]] = {
|
|
549
|
+
"agentMessage": (
|
|
550
|
+
(),
|
|
551
|
+
(lambda s, i: _text_part(s, "text", _required_text(i.get("text"), "params.item.text")),),
|
|
552
|
+
),
|
|
553
|
+
"reasoning": ((), (_reasoning_parts,)),
|
|
554
|
+
"plan": (
|
|
555
|
+
(),
|
|
556
|
+
(
|
|
557
|
+
lambda s, i: _text_part(
|
|
558
|
+
s, "plan_text", _required_text(i.get("text"), "params.item.text")
|
|
559
|
+
),
|
|
560
|
+
),
|
|
561
|
+
),
|
|
562
|
+
"commandExecution": ((_command_call,), (_command_call, _command_result)),
|
|
563
|
+
"mcpToolCall": ((_mcp_call,), (_mcp_call, _mcp_result)),
|
|
564
|
+
"fileChange": ((_file_change,), (_file_change,)),
|
|
565
|
+
"dynamicToolCall": ((_additional_tool_call,), (_additional_tool_call, _additional_tool_result)),
|
|
566
|
+
"collabAgentToolCall": (
|
|
567
|
+
(_additional_tool_call,),
|
|
568
|
+
(_additional_tool_call, _additional_tool_result),
|
|
569
|
+
),
|
|
570
|
+
"webSearch": ((_additional_tool_call,), (_additional_tool_call, _additional_tool_result)),
|
|
571
|
+
"imageGeneration": ((_image_artifact,), (_image_artifact,)),
|
|
572
|
+
**{
|
|
573
|
+
kind: ((_generic_item_data,), (_generic_item_data,))
|
|
574
|
+
for kind in _CODEX_0_144_4_DATA_ITEM_KINDS
|
|
575
|
+
},
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def _build_snapshot(
|
|
580
|
+
state: _ItemState, item: Mapping[str, Any], *, completed: bool
|
|
581
|
+
) -> ContentSnapshot:
|
|
582
|
+
builders = _ITEM_SNAPSHOT_BUILDERS[state.native_item_kind][1 if completed else 0]
|
|
583
|
+
parts: tuple[Any, ...] = ()
|
|
584
|
+
for builder in builders:
|
|
585
|
+
built = builder(state, item)
|
|
586
|
+
parts += built if isinstance(built, tuple) else (built,)
|
|
587
|
+
return ContentSnapshot(parts=parts)
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def _initial_snapshot(state: _ItemState, item: Mapping[str, Any]) -> ContentSnapshot | None:
|
|
591
|
+
if state.native_item_kind in {"agentMessage", "reasoning", "plan"}:
|
|
592
|
+
return None
|
|
593
|
+
return _build_snapshot(state, item, completed=False)
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def _completed_snapshot(state: _ItemState, item: Mapping[str, Any]) -> ContentSnapshot:
|
|
597
|
+
return _build_snapshot(state, item, completed=True)
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def _item_update(
|
|
601
|
+
method: str,
|
|
602
|
+
params: Mapping[str, Any],
|
|
603
|
+
state: _ItemState,
|
|
604
|
+
) -> tuple[Literal["append", "replace"], ContentValue]:
|
|
605
|
+
rule = _ITEM_UPDATE_RULES.get(method)
|
|
606
|
+
if rule is None or state.native_item_kind != rule[0]:
|
|
607
|
+
_fail(
|
|
608
|
+
"unsupported_item_mutation",
|
|
609
|
+
"method",
|
|
610
|
+
f"Codex method {method!r} does not match {state.native_item_kind!r}",
|
|
611
|
+
)
|
|
612
|
+
return rule[1](state, params)
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
def _delta(part_kind: str, field_name: str) -> Callable[..., tuple[Literal["append"], TextContent]]:
|
|
616
|
+
def build(
|
|
617
|
+
state: _ItemState, params: Mapping[str, Any]
|
|
618
|
+
) -> tuple[Literal["append"], TextContent]:
|
|
619
|
+
return (
|
|
620
|
+
"append",
|
|
621
|
+
TextContent(
|
|
622
|
+
part_id=_part_id(state, part_kind, "primary"),
|
|
623
|
+
text=_required_text(params.get("delta"), field_name),
|
|
624
|
+
),
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
return build
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
def _indexed_delta(
|
|
631
|
+
part_kind: str,
|
|
632
|
+
) -> Callable[..., tuple[Literal["append"], TextContent]]:
|
|
633
|
+
def build(
|
|
634
|
+
state: _ItemState, params: Mapping[str, Any]
|
|
635
|
+
) -> tuple[Literal["append"], TextContent]:
|
|
636
|
+
index = _nonnegative_int(params.get("contentIndex"), "params.contentIndex")
|
|
637
|
+
return (
|
|
638
|
+
"append",
|
|
639
|
+
TextContent(
|
|
640
|
+
part_id=_part_id(state, part_kind, str(index)),
|
|
641
|
+
text=_required_text(params.get("delta"), "params.delta"),
|
|
642
|
+
),
|
|
643
|
+
)
|
|
644
|
+
|
|
645
|
+
return build
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
def _summary_update(
|
|
649
|
+
part_added: bool,
|
|
650
|
+
) -> Callable[..., tuple[Literal["append", "replace"], TextContent]]:
|
|
651
|
+
def build(
|
|
652
|
+
state: _ItemState, params: Mapping[str, Any]
|
|
653
|
+
) -> tuple[Literal["append", "replace"], TextContent]:
|
|
654
|
+
summary_index = _nonnegative_int(params.get("summaryIndex"), "params.summaryIndex")
|
|
655
|
+
delta = "" if part_added else _required_text(params.get("delta"), "params.delta")
|
|
656
|
+
return (
|
|
657
|
+
"replace" if part_added else "append",
|
|
658
|
+
TextContent(
|
|
659
|
+
part_id=_part_id(state, "reasoning_summary", str(summary_index)),
|
|
660
|
+
text=delta,
|
|
661
|
+
),
|
|
662
|
+
)
|
|
663
|
+
|
|
664
|
+
return build
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
def _mcp_progress(
|
|
668
|
+
state: _ItemState, params: Mapping[str, Any]
|
|
669
|
+
) -> tuple[Literal["replace"], TextContent]:
|
|
670
|
+
return (
|
|
671
|
+
"replace",
|
|
672
|
+
TextContent(
|
|
673
|
+
part_id=_part_id(state, "mcp_progress", "primary"),
|
|
674
|
+
text=_required_text(params.get("message"), "params.message"),
|
|
675
|
+
),
|
|
676
|
+
)
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
def _patch_updated(
|
|
680
|
+
state: _ItemState, params: Mapping[str, Any]
|
|
681
|
+
) -> tuple[Literal["replace"], DataContent]:
|
|
682
|
+
changes = _json_value(params.get("changes"))
|
|
683
|
+
if not isinstance(changes, list):
|
|
684
|
+
_fail("invalid_item_update", "params.changes", "Codex file changes must be an array")
|
|
685
|
+
return (
|
|
686
|
+
"replace",
|
|
687
|
+
DataContent(
|
|
688
|
+
part_id=_part_id(state, "file_changes", "primary"),
|
|
689
|
+
data={"changes": changes, "status": "inProgress"},
|
|
690
|
+
),
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
# method -> (expected native item kind, update builder)
|
|
695
|
+
_ITEM_UPDATE_RULES: dict[
|
|
696
|
+
str,
|
|
697
|
+
tuple[
|
|
698
|
+
str,
|
|
699
|
+
Callable[
|
|
700
|
+
[_ItemState, Mapping[str, Any]],
|
|
701
|
+
tuple[Literal["append", "replace"], ContentValue],
|
|
702
|
+
],
|
|
703
|
+
],
|
|
704
|
+
] = {
|
|
705
|
+
"item/agentMessage/delta": ("agentMessage", _delta("text", "params.delta")),
|
|
706
|
+
"item/reasoning/textDelta": ("reasoning", _indexed_delta("reasoning_content")),
|
|
707
|
+
"item/reasoning/summaryPartAdded": ("reasoning", _summary_update(part_added=True)),
|
|
708
|
+
"item/reasoning/summaryTextDelta": ("reasoning", _summary_update(part_added=False)),
|
|
709
|
+
"item/commandExecution/outputDelta": (
|
|
710
|
+
"commandExecution",
|
|
711
|
+
_delta("command_output", "params.delta"),
|
|
712
|
+
),
|
|
713
|
+
"item/fileChange/outputDelta": ("fileChange", _delta("file_output", "params.delta")),
|
|
714
|
+
"item/plan/delta": ("plan", _delta("plan_text", "params.delta")),
|
|
715
|
+
"item/mcpToolCall/progress": ("mcpToolCall", _mcp_progress),
|
|
716
|
+
"item/fileChange/patchUpdated": ("fileChange", _patch_updated),
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
def _item_failed(state: _ItemState, item: Mapping[str, Any]) -> bool:
|
|
721
|
+
fail_statuses = _ITEM_FAIL_STATUSES.get(state.native_item_kind)
|
|
722
|
+
return fail_statuses is not None and item.get("status") in fail_statuses
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
def _source(method: str, cursor: str, state: _ItemState) -> SourceRef:
|
|
726
|
+
source = _protocol_source(
|
|
727
|
+
method=method,
|
|
728
|
+
cursor=cursor,
|
|
729
|
+
thread_id=state.thread_id,
|
|
730
|
+
turn_id=state.turn_id,
|
|
731
|
+
native_item_id=state.native_item_id,
|
|
732
|
+
)
|
|
733
|
+
return source.model_copy(
|
|
734
|
+
update={"metadata": {**source.metadata, "native_item_kind": state.native_item_kind}}
|
|
735
|
+
)
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
def _protocol_source(
|
|
739
|
+
*,
|
|
740
|
+
method: str,
|
|
741
|
+
cursor: str,
|
|
742
|
+
thread_id: str,
|
|
743
|
+
turn_id: str,
|
|
744
|
+
native_item_id: str | None,
|
|
745
|
+
native_event_id: str | None = None,
|
|
746
|
+
) -> SourceRef:
|
|
747
|
+
return SourceRef(
|
|
748
|
+
framework="codex",
|
|
749
|
+
native_event_id=native_event_id,
|
|
750
|
+
native_cursor=cursor,
|
|
751
|
+
native_run_id=turn_id,
|
|
752
|
+
native_item_id=native_item_id,
|
|
753
|
+
metadata=cast(
|
|
754
|
+
dict[str, JsonValue],
|
|
755
|
+
{
|
|
756
|
+
"app_server_version": _installed_app_server_version(),
|
|
757
|
+
"method": method,
|
|
758
|
+
"thread_id": thread_id,
|
|
759
|
+
"turn_id": turn_id,
|
|
760
|
+
"cursor_semantics": "jsonl",
|
|
761
|
+
},
|
|
762
|
+
),
|
|
763
|
+
)
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
@lru_cache(maxsize=1)
|
|
767
|
+
def _installed_app_server_version() -> str:
|
|
768
|
+
"""Report the packaged Codex runtime version instead of a stale constant."""
|
|
769
|
+
|
|
770
|
+
try:
|
|
771
|
+
return version("openai-codex")
|
|
772
|
+
except PackageNotFoundError:
|
|
773
|
+
return "unknown"
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
def _thread_continuation_identity(thread_id: str) -> tuple[str, str]:
|
|
777
|
+
scope_id = stable_scope_id("codex", thread_id, "thread_resume")
|
|
778
|
+
return scope_id, stable_item_id("codex", scope_id, "thread_resume", thread_id)
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
def _envelope(
|
|
782
|
+
context: CodexAdapterContext,
|
|
783
|
+
cursor: str,
|
|
784
|
+
timestamp: float,
|
|
785
|
+
) -> Callable[[str, str, str, str, SourceRef], dict[str, Any]]:
|
|
786
|
+
def env(
|
|
787
|
+
scope_id: str, identity: str, event_type: str, part_id: str, source: SourceRef
|
|
788
|
+
) -> dict[str, Any]:
|
|
789
|
+
return {
|
|
790
|
+
"schema_version": 2,
|
|
791
|
+
"event_id": stable_event_id(
|
|
792
|
+
"codex", scope_id, identity, event_type, part_id, cursor, 0
|
|
793
|
+
),
|
|
794
|
+
"seq": context.allocate_placeholder_seq(),
|
|
795
|
+
"timestamp": timestamp,
|
|
796
|
+
"run_id": context.run_id,
|
|
797
|
+
"scope_id": scope_id,
|
|
798
|
+
"source": source,
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
return env
|