agentengine-sdk-python 0.8.1__py3-none-any.whl → 0.8.3__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.
Files changed (476) hide show
  1. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/METADATA +25 -12
  2. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/RECORD +421 -232
  3. ksadk/_build_provenance.json +1 -0
  4. ksadk/a2a/_space_client_events.py +381 -0
  5. ksadk/a2a/event_adapter.py +156 -64
  6. ksadk/a2a/executor.py +179 -63
  7. ksadk/a2a/space_client.py +6 -333
  8. ksadk/a2ui/core.py +222 -53
  9. ksadk/agui/_agent_helpers.py +247 -0
  10. ksadk/agui/a2ui_projection.py +12 -5
  11. ksadk/agui/agent.py +443 -259
  12. ksadk/api/client.py +528 -27
  13. ksadk/builders/code_builder.py +284 -8
  14. ksadk/builders/container_builder.py +8 -1
  15. ksadk/builders/managed_runtime_builder.py +42 -35
  16. ksadk/cli/__init__.py +23 -0
  17. ksadk/cli/cmd_dashboard.py +15 -1
  18. ksadk/cli/cmd_deploy.py +10 -2
  19. ksadk/cli/cmd_eval.py +66 -9
  20. ksadk/cli/cmd_evalset.py +284 -0
  21. ksadk/cli/cmd_files.py +5 -1
  22. ksadk/cli/cmd_hermes.py +1 -126
  23. ksadk/cli/cmd_invoke.py +28 -38
  24. ksadk/cli/cmd_managed_runtime.py +95 -0
  25. ksadk/cli/cmd_observe.py +85 -0
  26. ksadk/cli/cmd_openclaw.py +1 -435
  27. ksadk/cli/cmd_plugin.py +657 -0
  28. ksadk/cli/cmd_replay.py +28 -4
  29. ksadk/cli/cmd_studio.py +99 -8
  30. ksadk/cli/cmd_web.py +10 -2
  31. ksadk/cli/hermes_env.py +151 -0
  32. ksadk/cli/invoke_payload.py +49 -0
  33. ksadk/cli/openclaw_env.py +458 -0
  34. ksadk/codex/client.py +180 -30
  35. ksadk/codex/runtime.py +475 -331
  36. ksadk/configs/env_registry.py +94 -12
  37. ksadk/configs/env_registry_pcm.py +181 -0
  38. ksadk/configs/env_var_spec.py +18 -0
  39. ksadk/configs/global_config.py +5 -0
  40. ksadk/configs/settings.py +9 -0
  41. ksadk/context_engine/__init__.py +98 -0
  42. ksadk/context_engine/assembler.py +176 -0
  43. ksadk/context_engine/baseline.py +419 -0
  44. ksadk/context_engine/cache_observability.py +228 -0
  45. ksadk/context_engine/capabilities.py +443 -0
  46. ksadk/context_engine/contributors.py +409 -0
  47. ksadk/context_engine/hosted_pipeline.py +417 -0
  48. ksadk/context_engine/models.py +117 -0
  49. ksadk/context_engine/planner.py +698 -0
  50. ksadk/context_engine/policies.py +319 -0
  51. ksadk/context_engine/projection.py +31 -0
  52. ksadk/context_engine/shadow_plan.py +266 -0
  53. ksadk/context_engine/tokenizer.py +164 -0
  54. ksadk/conversations/__init__.py +19 -0
  55. ksadk/conversations/context.py +230 -30
  56. ksadk/conversations/contracts.py +266 -0
  57. ksadk/conversations/message_projection.py +308 -26
  58. ksadk/conversations/model_context.py +49 -3
  59. ksadk/conversations/projector.py +616 -0
  60. ksadk/conversations/reducer.py +98 -0
  61. ksadk/conversations/runtime_compaction.py +207 -5
  62. ksadk/conversations/runtime_input.py +184 -2
  63. ksadk/conversations/runtime_invocation.py +81 -3
  64. ksadk/conversations/runtime_observability.py +141 -0
  65. ksadk/conversations/runtime_payloads.py +42 -0
  66. ksadk/conversations/runtime_preparation.py +272 -2
  67. ksadk/conversations/runtime_resume.py +20 -1
  68. ksadk/conversations/runtime_stream_events.py +94 -9
  69. ksadk/conversations/semantic_summary.py +311 -1
  70. ksadk/conversations/session_lock.py +51 -0
  71. ksadk/deployment/env_forward.py +72 -0
  72. ksadk/deployment/managed_runtime.py +5 -0
  73. ksadk/deployment/providers/serverless.py +143 -69
  74. ksadk/evaluation/__init__.py +32 -0
  75. ksadk/evaluation/a2a_adapter.py +9 -1
  76. ksadk/evaluation/adapters.py +18 -5
  77. ksadk/evaluation/agent_eval_client.py +395 -0
  78. ksadk/evaluation/cloud_binding.py +80 -0
  79. ksadk/evaluation/cloud_converter.py +194 -0
  80. ksadk/evaluation/cloud_service.py +199 -0
  81. ksadk/evaluation/contracts.py +73 -4
  82. ksadk/evaluation/evaluators.py +183 -17
  83. ksadk/evaluation/evidence.py +258 -0
  84. ksadk/evaluation/executor.py +31 -6
  85. ksadk/evaluation/local_adapter.py +550 -0
  86. ksadk/evaluation/service_env.py +27 -0
  87. ksadk/evaluation/studio_build_adapter.py +253 -0
  88. ksadk/evaluation/target.py +15 -6
  89. ksadk/events/__init__.py +13 -13
  90. ksadk/events/_v1_compat/__init__.py +1 -0
  91. ksadk/events/_v1_compat/models.py +299 -0
  92. ksadk/events/_v1_compat/parser.py +247 -0
  93. ksadk/events/_v1_compat/projection.py +755 -0
  94. ksadk/events/adapters/__init__.py +34 -0
  95. ksadk/events/adapters/_a2a_snapshot.py +622 -0
  96. ksadk/events/adapters/_a2a_support.py +275 -0
  97. ksadk/events/adapters/_codex_interactions.py +375 -0
  98. ksadk/events/adapters/_codex_items.py +801 -0
  99. ksadk/events/adapters/_codex_validators.py +311 -0
  100. ksadk/events/adapters/_langgraph_support.py +785 -0
  101. ksadk/events/adapters/a2a.py +841 -0
  102. ksadk/events/adapters/adk.py +503 -0
  103. ksadk/events/adapters/codex.py +907 -0
  104. ksadk/events/adapters/langgraph.py +745 -0
  105. ksadk/events/canonical.py +440 -0
  106. ksadk/events/canonical_replay.py +497 -0
  107. ksadk/events/canonical_store.py +468 -0
  108. ksadk/events/cold_recovery.py +257 -0
  109. ksadk/events/content.py +89 -0
  110. ksadk/events/identity.py +86 -0
  111. ksadk/events/pipeline.py +455 -0
  112. ksadk/events/projections.py +66 -0
  113. ksadk/events/reducer.py +661 -0
  114. ksadk/events/replay.py +3 -36
  115. ksadk/events/runtime_event.py +20 -265
  116. ksadk/events/session_event.py +324 -0
  117. ksadk/events/store.py +3 -316
  118. ksadk/events/v1_compat.py +41 -0
  119. ksadk/harness/__init__.py +45 -35
  120. ksadk/harness/runtime.py +220 -58
  121. ksadk/identity/resolver.py +4 -3
  122. ksadk/interaction/__init__.py +28 -0
  123. ksadk/interaction/contracts.py +136 -0
  124. ksadk/interaction/ledger.py +189 -0
  125. ksadk/interaction/provider.py +122 -0
  126. ksadk/interaction/providers/__init__.py +52 -0
  127. ksadk/interaction/providers/adk.py +40 -0
  128. ksadk/interaction/providers/codex.py +94 -0
  129. ksadk/interaction/providers/langgraph.py +58 -0
  130. ksadk/kernel/__init__.py +117 -0
  131. ksadk/kernel/authorization.py +258 -0
  132. ksadk/kernel/bootstrap.py +1074 -0
  133. ksadk/kernel/contract_fingerprints.py +62 -0
  134. ksadk/kernel/contracts.py +370 -0
  135. ksadk/kernel/control.py +220 -0
  136. ksadk/kernel/errors.py +79 -0
  137. ksadk/kernel/ingress.py +1123 -0
  138. ksadk/kernel/mapping.py +111 -0
  139. ksadk/kernel/memory_store.py +1134 -0
  140. ksadk/kernel/postgres_store.py +1757 -0
  141. ksadk/kernel/recovery.py +452 -0
  142. ksadk/kernel/runtime_identity.py +103 -0
  143. ksadk/kernel/sql/001_agent_kernel.sql +120 -0
  144. ksadk/kernel/sqlite_store.py +1411 -0
  145. ksadk/kernel/state.py +145 -0
  146. ksadk/kernel/store.py +232 -0
  147. ksadk/kernel/worker.py +964 -0
  148. ksadk/knowledge_base/client.py +7 -0
  149. ksadk/knowledge_base/service.py +32 -5
  150. ksadk/memory/__init__.py +61 -0
  151. ksadk/memory/adk/backends/base_ltm_backend.py +96 -1
  152. ksadk/memory/adk/backends/http_ltm_backend.py +14 -5
  153. ksadk/memory/adk/backends/inmemory_ltm_backend.py +136 -3
  154. ksadk/memory/adk/backends/sdk_ltm_backend.py +384 -2
  155. ksadk/memory/adk/backends/sqlite_ltm_backend.py +95 -0
  156. ksadk/memory/coordinator.py +461 -0
  157. ksadk/memory/events.py +202 -0
  158. ksadk/memory/extraction.py +228 -0
  159. ksadk/memory/ltm_backend_factory.py +16 -3
  160. ksadk/memory/models.py +316 -0
  161. ksadk/memory/policy.py +215 -0
  162. ksadk/memory/provider.py +47 -0
  163. ksadk/memory/provider_adapter.py +159 -0
  164. ksadk/memory/provider_resolver.py +71 -0
  165. ksadk/memory/providers/__init__.py +5 -0
  166. ksadk/memory/providers/local_sqlite.py +497 -0
  167. ksadk/memory/resolved_policy.py +145 -0
  168. ksadk/memory/service.py +188 -6
  169. ksadk/model_proxy/bootstrap.py +16 -9
  170. ksadk/model_proxy/detect.py +202 -9
  171. ksadk/model_proxy/namespace.py +39 -15
  172. ksadk/model_proxy/server.py +24 -5
  173. ksadk/model_proxy/transform.py +60 -2
  174. ksadk/observability/__init__.py +25 -0
  175. ksadk/observability/session_log.py +420 -0
  176. ksadk/observability/trajectory.py +105 -0
  177. ksadk/plugins/__init__.py +167 -0
  178. ksadk/plugins/bridges/__init__.py +45 -0
  179. ksadk/plugins/bridges/codex.py +552 -0
  180. ksadk/plugins/bridges/dsh.py +1116 -0
  181. ksadk/plugins/builtins.py +747 -0
  182. ksadk/plugins/bundle.py +246 -0
  183. ksadk/plugins/bundle_security.py +167 -0
  184. ksadk/plugins/composition.py +529 -0
  185. ksadk/plugins/context_contributor.py +437 -0
  186. ksadk/plugins/contracts.py +451 -0
  187. ksadk/plugins/dsh_toolchain.py +935 -0
  188. ksadk/plugins/ecosystem_bridge.py +1105 -0
  189. ksadk/plugins/ecosystem_probe.py +191 -0
  190. ksadk/plugins/host.py +724 -0
  191. ksadk/plugins/providers/__init__.py +85 -0
  192. ksadk/plugins/providers/bundles/ksadk-codex/cordis.patch.yml +3 -0
  193. ksadk/plugins/providers/bundles/ksadk-codex/index.mjs +18 -0
  194. ksadk/plugins/providers/bundles/ksadk-codex/package.json +19 -0
  195. ksadk/plugins/providers/bundles/ksadk-harness/cordis.patch.yml +3 -0
  196. ksadk/plugins/providers/bundles/ksadk-harness/index.mjs +19 -0
  197. ksadk/plugins/providers/bundles/ksadk-harness/package.json +19 -0
  198. ksadk/plugins/providers/codex.py +722 -0
  199. ksadk/plugins/providers/codex_dsh.py +83 -0
  200. ksadk/plugins/providers/dsh.py +951 -0
  201. ksadk/plugins/providers/dsh_descriptor_host.py +226 -0
  202. ksadk/plugins/providers/harness.py +627 -0
  203. ksadk/plugins/providers/harness_dsh.py +91 -0
  204. ksadk/plugins/providers/legacy.py +215 -0
  205. ksadk/plugins/providers/legacy_catalog.py +100 -0
  206. ksadk/plugins/providers/shipped_dsh.py +370 -0
  207. ksadk/plugins/resolver.py +331 -0
  208. ksadk/plugins/subagent_providers/__init__.py +12 -0
  209. ksadk/plugins/subagent_providers/codex.py +443 -0
  210. ksadk/plugins/subagents.py +333 -0
  211. ksadk/prompts/__init__.py +71 -0
  212. ksadk/prompts/compiler.py +215 -0
  213. ksadk/prompts/models.py +82 -0
  214. ksadk/prompts/projection.py +89 -0
  215. ksadk/prompts/resolved.py +137 -0
  216. ksadk/prompts/sources.py +233 -0
  217. ksadk/runners/_langgraph_runner_streams.py +822 -0
  218. ksadk/runners/adk_runner.py +5 -5
  219. ksadk/runners/base_runner.py +16 -0
  220. ksadk/runners/factory.py +1 -2
  221. ksadk/runners/langgraph_runner.py +198 -437
  222. ksadk/runtime/_runner_adapter/__init__.py +1 -0
  223. ksadk/runtime/_runner_adapter/stream_mapping.py +797 -0
  224. ksadk/runtime/adapter.py +119 -2
  225. ksadk/runtime/conversation_execution.py +316 -182
  226. ksadk/runtime/executor.py +144 -3
  227. ksadk/runtime/factory.py +268 -8
  228. ksadk/runtime/framework_adapters.py +18 -0
  229. ksadk/runtime/hosted_finalizer.py +268 -0
  230. ksadk/runtime/launch.py +14 -1
  231. ksadk/runtime/preprocessing.py +25 -3
  232. ksadk/runtime/runner_adapter.py +293 -508
  233. ksadk/runtime/usage.py +33 -0
  234. ksadk/sandbox/__init__.py +2 -1
  235. ksadk/sandbox/backends/e2b.py +35 -2
  236. ksadk/sandbox/factory.py +72 -0
  237. ksadk/scheduler/__init__.py +18 -0
  238. ksadk/scheduler/calendar.py +102 -0
  239. ksadk/scheduler/contracts.py +254 -0
  240. ksadk/scheduler/dispatcher.py +129 -0
  241. ksadk/scheduler/engine.py +416 -0
  242. ksadk/scheduler/sqlite_store.py +563 -0
  243. ksadk/server/composition.py +8 -0
  244. ksadk/server/factory.py +69 -6
  245. ksadk/server/routes/kernel_ingress.py +258 -0
  246. ksadk/server/routes/openai_compat.py +88 -8
  247. ksadk/server/routes/projection.py +35 -20
  248. ksadk/server/routes/run.py +94 -0
  249. ksadk/server/routes/sessions.py +2 -0
  250. ksadk/server/routes/streaming.py +5 -2
  251. ksadk/server/static/assets/{ArtifactsPanel-CakCqxEN.js → ArtifactsPanel-10GPXIJ6.js} +1 -1
  252. ksadk/server/static/assets/{CodeBlock-CynLknyO.js → CodeBlock-BXk1l-G1.js} +4 -4
  253. ksadk/server/static/assets/MathMessageMarkdown-BorAY7qD.css +1 -0
  254. ksadk/server/static/assets/{MathMessageMarkdown-3sQdOysS.js → MathMessageMarkdown-D9uB55Oh.js} +4 -4
  255. ksadk/server/static/assets/MermaidBlock--OEYoXIJ.js +312 -0
  256. ksadk/server/static/assets/NativeTerminalPanel-DrEe1syq.js +1 -0
  257. ksadk/server/static/assets/abnfDiagram-VCTEODGH-eeTFJLvo.js +1 -0
  258. ksadk/server/static/assets/arc-S3ZNbIAd.js +1 -0
  259. ksadk/server/static/assets/architecture-7GRP2DOG-Dk9nRQ6-.js +1 -0
  260. ksadk/server/static/assets/architectureDiagram-5GKGNRK7-CRjgEJDX.js +36 -0
  261. ksadk/server/static/assets/blockDiagram-NRAW4CY4-C7bsBoNH.js +129 -0
  262. ksadk/server/static/assets/c4Diagram-UCG6FXSJ-BX3c33Ob.js +38 -0
  263. ksadk/server/static/assets/channel-s354Yo6o.js +1 -0
  264. ksadk/server/static/assets/chunk-2Q5K7J3B-CDpPpKR5.js +1 -0
  265. ksadk/server/static/assets/{chunk-FMBD7UC4-B_fH2YuH.js → chunk-5VM5RSS4-bZ7ws-8m.js} +1 -1
  266. ksadk/server/static/assets/{chunk-ND2GUHAM-D6rFLaVV.js → chunk-F27PBJKO-D2r0pvhY.js} +1 -1
  267. ksadk/server/static/assets/chunk-G27WJ6UU-CZwF3oUP.js +231 -0
  268. ksadk/server/static/assets/{chunk-4BX2VUAB-B9drTgOW.js → chunk-JWPE2WC7-DigFYCML.js} +1 -1
  269. ksadk/server/static/assets/chunk-LCL6LL3I-CnorGV5q.js +206 -0
  270. ksadk/server/static/assets/chunk-POPQ4Y6H-CexntQA-.js +1 -0
  271. ksadk/server/static/assets/chunk-RHFEMEQ7-CHTC7UxA.js +168 -0
  272. ksadk/server/static/assets/chunk-SVP7TREG-BC1EWt_-.js +88 -0
  273. ksadk/server/static/assets/chunk-XXDRQBXY-BTG24xN0.js +1 -0
  274. ksadk/server/static/assets/classDiagram-DTDB5LWJ-Dd0nucl9.js +1 -0
  275. ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-Dd0nucl9.js +1 -0
  276. ksadk/server/static/assets/{cose-bilkent-S5V4N54A-ChNs_Mdk.js → cose-bilkent-JH36ORCC-CkonRdAS.js} +1 -1
  277. ksadk/server/static/assets/cynefin-OW5HDTMX-BBlT4uMf.js +1 -0
  278. ksadk/server/static/assets/cynefinDiagram-5FMLGOSQ-DEOCBe15.js +62 -0
  279. ksadk/server/static/assets/cytoscape.esm-CyCl8rPi.js +321 -0
  280. ksadk/server/static/assets/dagre-3AP2YEHR-DBThPuLa.js +4 -0
  281. ksadk/server/static/assets/dagre-ClTPrTht.js +1 -0
  282. ksadk/server/static/assets/diagram-S7CK7UJ4-DsZHrnpJ.js +30 -0
  283. ksadk/server/static/assets/diagram-UQ7AKVKN-BJR4nhVr.js +41 -0
  284. ksadk/server/static/assets/diagram-VSXAHHWV-xzcERX0a.js +3 -0
  285. ksadk/server/static/assets/diagram-VX7I27RA-tn2xM1xu.js +24 -0
  286. ksadk/server/static/assets/diagram-Z3DM3KII-BZPGBkw5.js +24 -0
  287. ksadk/server/static/assets/{dist-gLnrGsoU.js → dist-4zN1_tq5.js} +1 -1
  288. ksadk/server/static/assets/{dist-C1sz5Eo3.js → dist-8VWI-2bZ.js} +1 -1
  289. ksadk/server/static/assets/{dist-BjOdlDjj.js → dist-B-46q3Hk.js} +1 -1
  290. ksadk/server/static/assets/{dist-o2OVmKvt.js → dist-B0gdk4rl.js} +1 -1
  291. ksadk/server/static/assets/{dist-4N2NMVYg.js → dist-B1oWRmrH.js} +1 -1
  292. ksadk/server/static/assets/{dist-CmZHzlwZ.js → dist-BI1qQH4n.js} +1 -1
  293. ksadk/server/static/assets/{dist-X4TnqwOK.js → dist-BJLUwH6W.js} +1 -1
  294. ksadk/server/static/assets/{dist-B5oS1zcj.js → dist-Bbwqa8TG.js} +1 -1
  295. ksadk/server/static/assets/{dist-j6Dxmf_j.js → dist-Btyo4vX4.js} +1 -1
  296. ksadk/server/static/assets/{dist-DQU9EWw-.js → dist-C71CsujO.js} +1 -1
  297. ksadk/server/static/assets/{dist-BIlKoW0k.js → dist-CXpH_Rdd.js} +1 -1
  298. ksadk/server/static/assets/{dist-DJN_6Y39.js → dist-Cq4OL6nO.js} +1 -1
  299. ksadk/server/static/assets/{dist-Dli7qW-B.js → dist-D1V3f1B4.js} +1 -1
  300. ksadk/server/static/assets/{dist-fhOuWds5.js → dist-DJmCPRVB.js} +1 -1
  301. ksadk/server/static/assets/{dist-CWV4lDr1.js → dist-DQAB0qn_.js} +2 -2
  302. ksadk/server/static/assets/{dist-D6MpCZtz.js → dist-DUwKa_l6.js} +1 -1
  303. ksadk/server/static/assets/dist-DdRBIceA.js +1 -0
  304. ksadk/server/static/assets/{dist-DWKByxWV.js → dist-DfGFrb0v.js} +1 -1
  305. ksadk/server/static/assets/{dist-DsHPdk3W.js → dist-DjhwGUgZ.js} +1 -1
  306. ksadk/server/static/assets/{dist-B-jNR6Vn.js → dist-DyqV4fL4.js} +1 -1
  307. ksadk/server/static/assets/{dist-BB3-OwTQ.js → dist-M67Hwu0n.js} +1 -1
  308. ksadk/server/static/assets/{dist-_pHPTyZ-.js → dist-u8tVH5Ak.js} +1 -1
  309. ksadk/server/static/assets/ebnfDiagram-PWID7BFC-DVfMsLge.js +1 -0
  310. ksadk/server/static/assets/erDiagram-SSCWMZ5O-CWEZSYaw.js +99 -0
  311. ksadk/server/static/assets/eventmodeling-NTZA5JFV-Dr5okd8V.js +1 -0
  312. ksadk/server/static/assets/flowDiagram-A5DVABFB-VEO-cVcO.js +1 -0
  313. ksadk/server/static/assets/ganttDiagram-EL5Y4UJY-TWIxoyYL.js +292 -0
  314. ksadk/server/static/assets/gitGraph-4MIJSDKK-CKiKY9Cf.js +1 -0
  315. ksadk/server/static/assets/gitGraphDiagram-WWUBYQGX-DDh2hd2S.js +106 -0
  316. ksadk/server/static/assets/index-B2k_urY8.js +241 -0
  317. ksadk/server/static/assets/index-ILPt6IWF.css +2 -0
  318. ksadk/server/static/assets/info-A6RAGUB7-ubA4Nm_p.js +1 -0
  319. ksadk/server/static/assets/infoDiagram-RXCK75RN-CgoyWiDR.js +2 -0
  320. ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-K0OOfVna.js → ishikawaDiagram-5VMMS53U-CyRIu_om.js} +6 -6
  321. ksadk/server/static/assets/{journeyDiagram-JHISSGLW-8LeOJaZp.js → journeyDiagram-EYS64GPL-DN5JXHzN.js} +6 -6
  322. ksadk/server/static/assets/{kanban-definition-UN3LZRKU-C6uCgZrW.js → kanban-definition-3QL26DDD-CNP3ui66.js} +10 -10
  323. ksadk/server/static/assets/katex-DWEzQy1d.js +257 -0
  324. ksadk/server/static/assets/{linear-hdBcYzM8.js → linear-C-qHp7d2.js} +1 -1
  325. ksadk/server/static/assets/mermaid-parser.core-Cl-K943T.js +166 -0
  326. ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-Bjy_2v4_.js → mindmap-definition-FBJOCRG2-D5DB5mYm.js} +29 -29
  327. ksadk/server/static/assets/packet-AYTQ26CC-C7R3NUlK.js +1 -0
  328. ksadk/server/static/assets/pegDiagram-XKGWAZYB-BQVc9ia_.js +1 -0
  329. ksadk/server/static/assets/pie-WAS4IAKB-BIT6qjr3.js +1 -0
  330. ksadk/server/static/assets/pieDiagram-E7YTZNPT-B6UCAvtY.js +39 -0
  331. ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-BmkRbwCg.js → quadrantDiagram-AXDQQJYC-mIr2d3eb.js} +6 -6
  332. ksadk/server/static/assets/radar-RG4KPBEZ-l5noef9X.js +1 -0
  333. ksadk/server/static/assets/railroad-74A4TZTK-Baea6ZvM.js +1 -0
  334. ksadk/server/static/assets/railroad-abnf-HS5TGJTU-OKn8zZnU.js +1 -0
  335. ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-DdKAKC4l.js +1 -0
  336. ksadk/server/static/assets/railroad-peg-WCYAUIDC-Bds8udlG.js +1 -0
  337. ksadk/server/static/assets/railroadDiagram-O6MQD6OU-Dt3FFDmK.js +1 -0
  338. ksadk/server/static/assets/requirementDiagram-EFPCY7ZU-Cz_vQtgF.js +84 -0
  339. ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-l6iXmU65.js → sankeyDiagram-P5KCCOFB-wlO1TsH5.js} +7 -7
  340. ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-Cq6UBeQB.js → sequenceDiagram-WJ2MYXX4-CHRbElYq.js} +10 -10
  341. ksadk/server/static/assets/sizeCapture-X5ZJPWSS-DXX54iyO.js +1 -0
  342. ksadk/server/static/assets/stateDiagram-HBIQ2CUA-Dp_lw9II.js +1 -0
  343. ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-5b-8o2iS.js +1 -0
  344. ksadk/server/static/assets/swimlanes-XN3QIQJK-D8O5UlLG.js +1 -0
  345. ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-uf6WPRA4.js +8 -0
  346. ksadk/server/static/assets/{timeline-definition-PNZ67QCA-DEz24vV0.js → timeline-definition-24CTP7MA-8mfKcxvG.js} +7 -7
  347. ksadk/server/static/assets/treeView-Q6P3EWNA-CK5CSrSO.js +1 -0
  348. ksadk/server/static/assets/treemap-WGGIJYW6-Ch2BKgAM.js +1 -0
  349. ksadk/server/static/assets/vennDiagram-4TSXK5OY-EnNl0DE7.js +34 -0
  350. ksadk/server/static/assets/wardley-WFR3VGLG-YW3Q0ml_.js +1 -0
  351. ksadk/server/static/assets/wardleyDiagram-VM6X3IG4-DBu5fbYr.js +78 -0
  352. ksadk/server/static/assets/xychartDiagram-S5SC5T6Z-BSVXs4IY.js +7 -0
  353. ksadk/server/static/index.html +2 -2
  354. ksadk/sessions/__init__.py +26 -9
  355. ksadk/sessions/_local_service_sync.py +688 -0
  356. ksadk/sessions/_local_tables.py +21 -0
  357. ksadk/sessions/_postgres_schema.py +305 -0
  358. ksadk/sessions/_postgres_tables.py +15 -0
  359. ksadk/sessions/base.py +80 -1
  360. ksadk/sessions/in_memory.py +53 -2
  361. ksadk/sessions/local_service.py +63 -604
  362. ksadk/sessions/postgres_service.py +58 -148
  363. ksadk/sessions/resilient.py +35 -1
  364. ksadk/skills/service_client.py +48 -0
  365. ksadk/studio/agent_lifecycle.py +26 -20
  366. ksadk/studio/api.py +1063 -69
  367. ksadk/studio/api_catalog_routes.py +5 -0
  368. ksadk/studio/api_contracts.py +148 -6
  369. ksadk/studio/api_memory_routes.py +82 -0
  370. ksadk/studio/api_plugin_routes.py +480 -0
  371. ksadk/studio/attachment_store.py +187 -0
  372. ksadk/studio/authoring.py +259 -28
  373. ksadk/studio/authoring_coordinator.py +809 -67
  374. ksadk/studio/builder.py +197 -40
  375. ksadk/studio/capabilities.py +17 -0
  376. ksadk/studio/cloud.py +1920 -95
  377. ksadk/studio/codex_agent_service.py +137 -15
  378. ksadk/studio/codex_authoring.py +469 -0
  379. ksadk/studio/codex_builder.py +177 -25
  380. ksadk/studio/codex_manifest.py +71 -22
  381. ksadk/studio/codex_run.py +59 -4
  382. ksadk/studio/compatibility_report.py +445 -0
  383. ksadk/studio/compiler.py +7 -1
  384. ksadk/studio/contracts.py +234 -4
  385. ksadk/studio/dsh_provider_registration.py +768 -0
  386. ksadk/studio/event_store.py +79 -101
  387. ksadk/studio/framework_run.py +264 -3
  388. ksadk/studio/hosted_kernel.py +317 -0
  389. ksadk/studio/manifest_resolver.py +131 -0
  390. ksadk/studio/model_client.py +95 -9
  391. ksadk/studio/model_profile_service.py +1 -1
  392. ksadk/studio/operations.py +47 -5
  393. ksadk/studio/otel_trace.py +348 -42
  394. ksadk/studio/pcm_memory.py +85 -0
  395. ksadk/studio/plugin_composition.py +301 -0
  396. ksadk/studio/plugin_kernel_adapter.py +128 -0
  397. ksadk/studio/plugin_runtime.py +652 -0
  398. ksadk/studio/repository.py +23 -2
  399. ksadk/studio/resource_catalog.py +49 -1
  400. ksadk/studio/run_service.py +1266 -202
  401. ksadk/studio/runtime_source.py +51 -17
  402. ksadk/studio/scheduler_runtime.py +374 -0
  403. ksadk/studio/scheduler_service.py +211 -0
  404. ksadk/studio/service.py +1815 -117
  405. ksadk/studio/shared_web.py +199 -50
  406. ksadk/studio/soul.py +52 -0
  407. ksadk/studio/static/assets/index-DXs1Eq4M.css +1 -0
  408. ksadk/studio/static/assets/index-DeDqwTsD.js +283 -0
  409. ksadk/studio/static/index.html +2 -2
  410. ksadk/studio/templates.py +100 -8
  411. ksadk/studio/validator.py +20 -1
  412. ksadk/studio/workspace.py +31 -32
  413. ksadk/tracing/setup.py +304 -3
  414. ksadk/version.py +1 -1
  415. ksadk_runtime_common/schemas/runtime_event_v1.json +37 -0
  416. ksadk_runtime_common/schemas/runtime_event_v2.json +271 -0
  417. ksadk_runtime_common/workspace_files/path_utils.py +41 -0
  418. ksadk/events/parser.py +0 -191
  419. ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +0 -1
  420. ksadk/server/static/assets/MermaidBlock-NERD_ef7.js +0 -303
  421. ksadk/server/static/assets/NativeTerminalPanel-CiHWf82q.js +0 -1
  422. ksadk/server/static/assets/arc-DrgjcKhl.js +0 -1
  423. ksadk/server/static/assets/architecture-7EHR7CIX-CpZLRCcY.js +0 -1
  424. ksadk/server/static/assets/architectureDiagram-3BPJPVTR-BXoVRbQ6.js +0 -36
  425. ksadk/server/static/assets/blockDiagram-GPEHLZMM-BnaB3Ywv.js +0 -132
  426. ksadk/server/static/assets/c4Diagram-AAUBKEIU-Dw4weZcp.js +0 -10
  427. ksadk/server/static/assets/channel-Dt3rQTFI.js +0 -1
  428. ksadk/server/static/assets/chunk-2J33WTMH-ChjpLK7j.js +0 -1
  429. ksadk/server/static/assets/chunk-55IACEB6-CK4ROATy.js +0 -1
  430. ksadk/server/static/assets/chunk-727SXJPM-B9KtTTgw.js +0 -206
  431. ksadk/server/static/assets/chunk-AQP2D5EJ-1O1mki3m.js +0 -231
  432. ksadk/server/static/assets/chunk-QZHKN3VN-iXEZtKQc.js +0 -1
  433. ksadk/server/static/assets/classDiagram-4FO5ZUOK-DIveV17Q.js +0 -1
  434. ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-DIveV17Q.js +0 -1
  435. ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +0 -321
  436. ksadk/server/static/assets/dagre-BM42HDAG-D0QXg_MQ.js +0 -4
  437. ksadk/server/static/assets/dagre-Bx709z4p.js +0 -1
  438. ksadk/server/static/assets/diagram-2AECGRRQ-DBDDKwBQ.js +0 -43
  439. ksadk/server/static/assets/diagram-5GNKFQAL-BkwDOxmO.js +0 -10
  440. ksadk/server/static/assets/diagram-KO2AKTUF-Bv8waYvY.js +0 -3
  441. ksadk/server/static/assets/diagram-LMA3HP47-e1VECDdu.js +0 -24
  442. ksadk/server/static/assets/diagram-OG6HWLK6-Ds9adfRl.js +0 -24
  443. ksadk/server/static/assets/dist-B5J2uhNk.js +0 -1
  444. ksadk/server/static/assets/erDiagram-TEJ5UH35-BPItFKH6.js +0 -85
  445. ksadk/server/static/assets/eventmodeling-FCH6USID-DYFSxbqr.js +0 -1
  446. ksadk/server/static/assets/flowDiagram-I6XJVG4X-BbYB9w5Y.js +0 -162
  447. ksadk/server/static/assets/ganttDiagram-6RSMTGT7-TQXa0KXv.js +0 -292
  448. ksadk/server/static/assets/gitGraph-WXDBUCRP-DyNYp6BN.js +0 -1
  449. ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-bKblCnpa.js +0 -106
  450. ksadk/server/static/assets/graphlib-B8gBHxth.js +0 -1
  451. ksadk/server/static/assets/index-R52pJJvg.js +0 -177
  452. ksadk/server/static/assets/index-jJr3_955.css +0 -2
  453. ksadk/server/static/assets/info-J43DQDTF-WUx7qTde.js +0 -1
  454. ksadk/server/static/assets/infoDiagram-5YYISTIA-BGVT7J_i.js +0 -2
  455. ksadk/server/static/assets/katex-CYWseY5E.js +0 -265
  456. ksadk/server/static/assets/mermaid-parser.core-BWrDjSZM.js +0 -161
  457. ksadk/server/static/assets/packet-YPE3B663-BN13y_xl.js +0 -1
  458. ksadk/server/static/assets/pie-LRSECV5Y-ftSLXhhc.js +0 -1
  459. ksadk/server/static/assets/pieDiagram-4H26LBE5-GmmqNiVH.js +0 -30
  460. ksadk/server/static/assets/radar-GUYGQ44K-jaICkIeO.js +0 -1
  461. ksadk/server/static/assets/requirementDiagram-4Y6WPE33-DSWFqL7c.js +0 -84
  462. ksadk/server/static/assets/stateDiagram-AJRCARHV-qzTQpg3Y.js +0 -1
  463. ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-BYCoYGAN.js +0 -1
  464. ksadk/server/static/assets/treeView-BLDUP644-Cpib_vlz.js +0 -1
  465. ksadk/server/static/assets/treemap-LRROVOQU-DQxfmVHK.js +0 -1
  466. ksadk/server/static/assets/vennDiagram-CIIHVFJN-CMCixki2.js +0 -34
  467. ksadk/server/static/assets/wardley-L42UT6IY-BQYHnnkU.js +0 -1
  468. ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-CVzB8F9K.js +0 -78
  469. ksadk/server/static/assets/xychartDiagram-2RQKCTM6-BFBqBLc1.js +0 -7
  470. ksadk/studio/evaluation.py +0 -192
  471. ksadk/studio/static/assets/index-CaEN0eTR.css +0 -1
  472. ksadk/studio/static/assets/index-DI2eY_NH.js +0 -252
  473. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/WHEEL +0 -0
  474. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/entry_points.txt +0 -0
  475. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/licenses/LICENSE +0 -0
  476. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,907 @@
1
+ """Codex app-server 0.147.0 JSONL messages to RuntimeEvent schema v2."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import copy
6
+ import hashlib
7
+ import json
8
+ from collections import OrderedDict
9
+ from collections.abc import Iterable, Mapping, Sequence
10
+ from typing import Any, Callable
11
+
12
+ from ksadk.events.adapters._codex_interactions import _CodexInteractionMixin
13
+ from ksadk.events.adapters._codex_items import (
14
+ _CODEX_0_147_0_NOTIFICATION_METHODS,
15
+ _CONTROL_INTERACTION_METHODS,
16
+ _FAILURE_CODE_KINDS,
17
+ _INTERACTION_METHODS,
18
+ _ITEM_METHODS,
19
+ CodexAdapterContext,
20
+ _completed_snapshot,
21
+ _envelope,
22
+ _fail,
23
+ _initial_snapshot,
24
+ _InteractionState,
25
+ _item_failed,
26
+ _item_state,
27
+ _item_update,
28
+ _ItemState,
29
+ _part_id,
30
+ _protocol_source,
31
+ _ReplayRecord,
32
+ _source,
33
+ _thread_continuation_identity,
34
+ )
35
+ from ksadk.events.adapters._codex_validators import (
36
+ CodexMappingError as CodexMappingError, # noqa: F401
37
+ )
38
+ from ksadk.events.adapters._codex_validators import (
39
+ _json_value,
40
+ _mapping,
41
+ _nonnegative_int,
42
+ _request_id,
43
+ _required_string,
44
+ _required_text,
45
+ _safe_codex_error_info_kind,
46
+ )
47
+ from ksadk.events.canonical import (
48
+ ContinuationCreated,
49
+ ContinuationResumed,
50
+ ErrorInfo,
51
+ InteractionRequested,
52
+ ItemCompleted,
53
+ ItemFailed,
54
+ ItemStarted,
55
+ ItemUpdated,
56
+ OutputRef,
57
+ RunCanceled,
58
+ RunCompleted,
59
+ RunFailed,
60
+ RunInterrupted,
61
+ RunProgress,
62
+ RunStarted,
63
+ RuntimeEvent,
64
+ SourceRef,
65
+ StructuredInputRequest,
66
+ UsageReported,
67
+ )
68
+ from ksadk.events.content import (
69
+ ContentSnapshot,
70
+ DataContent,
71
+ )
72
+ from ksadk.events.identity import stable_item_id, stable_scope_id
73
+
74
+
75
+ class CodexEventAdapter(_CodexInteractionMixin):
76
+ """Map one source-owned Codex JSONL frame at a time."""
77
+
78
+ _REPLAY_WINDOW_LIMIT = 1024
79
+
80
+ def __init__(self, *, known_thread_ids: Iterable[str] = ()) -> None:
81
+ self._items: dict[tuple[str, str], _ItemState] = {}
82
+ self._active_turns: set[str] = set()
83
+ self._completed_items: dict[str, list[OutputRef]] = {}
84
+ self._interactions: dict[str, _InteractionState] = {}
85
+ self._thread_continuations: dict[str, str] = {
86
+ thread_id: _thread_continuation_identity(thread_id)[1]
87
+ for thread_id in known_thread_ids
88
+ if thread_id
89
+ }
90
+ self._resume_requests: dict[str, str] = {}
91
+ self._pending_resume_by_thread: dict[str, str] = {}
92
+ self._replay_window: OrderedDict[str, _ReplayRecord] = OrderedDict()
93
+
94
+ @property
95
+ def replay_window_limit(self) -> int:
96
+ """Maximum number of source mutation identities retained for replay safety."""
97
+
98
+ return self._REPLAY_WINDOW_LIMIT
99
+
100
+ @property
101
+ def replay_window_size(self) -> int:
102
+ """Current bounded replay identity count (exposed for diagnostics/tests)."""
103
+
104
+ return len(self._replay_window)
105
+
106
+ def map_protocol_message(
107
+ self,
108
+ message: Mapping[str, Any],
109
+ context: CodexAdapterContext,
110
+ *,
111
+ native_cursor: str,
112
+ timestamp: float,
113
+ ) -> tuple[RuntimeEvent, ...]:
114
+ cursor = _required_string(native_cursor, "native_cursor")
115
+ payload_digest = hashlib.sha256(
116
+ json.dumps(
117
+ _json_value(message),
118
+ ensure_ascii=False,
119
+ separators=(",", ":"),
120
+ sort_keys=True,
121
+ ).encode("utf-8")
122
+ ).hexdigest()
123
+ previous = self._replay_window.get(cursor)
124
+ if previous is not None:
125
+ if previous.payload_digest != payload_digest:
126
+ _fail(
127
+ "native_event_collision",
128
+ "native_cursor",
129
+ f"Codex native cursor {cursor!r} was reused with a different payload",
130
+ )
131
+ self._replay_window.move_to_end(cursor)
132
+ return ()
133
+ shadow = copy.deepcopy(self)
134
+ shadow_context = copy.deepcopy(context)
135
+ events = shadow._map_protocol_message(
136
+ message,
137
+ shadow_context,
138
+ cursor=cursor,
139
+ timestamp=timestamp,
140
+ )
141
+ shadow._replay_window[cursor] = _ReplayRecord(
142
+ payload_digest=payload_digest,
143
+ event_ids=tuple(event.event_id for event in events),
144
+ )
145
+ while len(shadow._replay_window) > self._REPLAY_WINDOW_LIMIT:
146
+ shadow._replay_window.popitem(last=False)
147
+ self.__dict__.clear()
148
+ self.__dict__.update(shadow.__dict__)
149
+ context._next_seq = shadow_context._next_seq
150
+ return events
151
+
152
+ def _map_protocol_message(
153
+ self,
154
+ message: Mapping[str, Any],
155
+ context: CodexAdapterContext,
156
+ *,
157
+ cursor: str,
158
+ timestamp: float,
159
+ ) -> tuple[RuntimeEvent, ...]:
160
+ if "method" not in message:
161
+ return self._map_jsonrpc_response(message, context, cursor, timestamp)
162
+
163
+ method = _required_string(message.get("method"), "method")
164
+ params = _mapping(message.get("params"), "params")
165
+ if method == "thread/resume":
166
+ request_id = _request_id(message.get("id"), "id")
167
+ thread_id = _required_string(params.get("threadId"), "params.threadId")
168
+ if thread_id in self._pending_resume_by_thread:
169
+ _fail(
170
+ "thread_resume_already_pending",
171
+ "params.threadId",
172
+ f"Codex thread {thread_id!r} already has a pending resume",
173
+ )
174
+ self._resume_requests[request_id] = thread_id
175
+ self._pending_resume_by_thread[thread_id] = request_id
176
+ return ()
177
+
178
+ if method in {"turn/started", "turn/completed"}:
179
+ return self._map_turn_event(
180
+ method=method,
181
+ params=params,
182
+ context=context,
183
+ cursor=cursor,
184
+ timestamp=timestamp,
185
+ )
186
+ if method == "thread/tokenUsage/updated":
187
+ return self._map_token_usage(
188
+ params=params,
189
+ context=context,
190
+ cursor=cursor,
191
+ timestamp=timestamp,
192
+ )
193
+ if method == "serverRequest/resolved":
194
+ return self._map_server_request_resolved(
195
+ params=params, context=context, cursor=cursor, timestamp=timestamp
196
+ )
197
+ if method == "a2ui/surface":
198
+ return self._map_a2ui_surface(
199
+ params=params,
200
+ context=context,
201
+ cursor=cursor,
202
+ timestamp=timestamp,
203
+ )
204
+ if method == "a2ui/interaction":
205
+ return self._map_a2ui_interaction(
206
+ params=params,
207
+ context=context,
208
+ cursor=cursor,
209
+ timestamp=timestamp,
210
+ )
211
+ if method in _CONTROL_INTERACTION_METHODS:
212
+ return self._map_control_interaction_request(
213
+ message=message,
214
+ method=method,
215
+ params=params,
216
+ context=context,
217
+ cursor=cursor,
218
+ timestamp=timestamp,
219
+ )
220
+ if method in _ITEM_METHODS or method in _INTERACTION_METHODS:
221
+ thread_id = _required_string(params.get("threadId"), "params.threadId")
222
+ turn_value = params.get("turnId")
223
+ interrupts_run = not (method == "mcpServer/elicitation/request" and turn_value is None)
224
+ turn_id = (
225
+ _required_string(turn_value, "params.turnId")
226
+ if interrupts_run
227
+ else "mcp_elicitation"
228
+ )
229
+ scope_id = stable_scope_id("codex", thread_id, turn_id)
230
+ env = _envelope(context, cursor, timestamp)
231
+
232
+ if method == "error":
233
+ return self._map_error(
234
+ params,
235
+ env,
236
+ scope_id=scope_id,
237
+ thread_id=thread_id,
238
+ turn_id=turn_id,
239
+ cursor=cursor,
240
+ )
241
+ if method == "item/started":
242
+ return self._map_item_started(
243
+ params,
244
+ env,
245
+ scope_id=scope_id,
246
+ thread_id=thread_id,
247
+ turn_id=turn_id,
248
+ cursor=cursor,
249
+ )
250
+ if method == "item/completed":
251
+ return self._map_item_terminal(
252
+ method, params, env, scope_id=scope_id, cursor=cursor
253
+ )
254
+ if method in _ITEM_METHODS:
255
+ return self._map_item_updated(method, params, env, scope_id=scope_id, cursor=cursor)
256
+ return self._map_interaction_request(
257
+ message=message,
258
+ method=method,
259
+ params=params,
260
+ env=env,
261
+ context=context,
262
+ cursor=cursor,
263
+ timestamp=timestamp,
264
+ thread_id=thread_id,
265
+ turn_id=turn_id,
266
+ scope_id=scope_id,
267
+ interrupts_run=interrupts_run,
268
+ )
269
+ if method in _CODEX_0_147_0_NOTIFICATION_METHODS:
270
+ return self._map_known_notification(
271
+ method=method, params=params, context=context, cursor=cursor, timestamp=timestamp
272
+ )
273
+ _fail("unsupported_method", "method", f"Unsupported Codex app-server method: {method}")
274
+
275
+ @staticmethod
276
+ def _a2ui_scope(
277
+ params: Mapping[str, Any],
278
+ context: CodexAdapterContext,
279
+ *,
280
+ surface_id: str,
281
+ ) -> tuple[str, str, str]:
282
+ thread_value = params.get("threadId", params.get("thread_id"))
283
+ turn_value = params.get("turnId", params.get("turn_id"))
284
+ thread_id = (
285
+ _required_string(thread_value, "params.threadId")
286
+ if thread_value is not None
287
+ else f"runtime:{context.run_id}"
288
+ )
289
+ turn_id = (
290
+ _required_string(turn_value, "params.turnId")
291
+ if turn_value is not None
292
+ else "a2ui"
293
+ )
294
+ return thread_id, turn_id, stable_scope_id("codex", thread_id, turn_id, surface_id)
295
+
296
+ @staticmethod
297
+ def _a2ui_source(
298
+ *,
299
+ method: str,
300
+ cursor: str,
301
+ thread_id: str,
302
+ turn_id: str,
303
+ native_item_id: str,
304
+ surface_id: str,
305
+ metadata: Mapping[str, Any] | None = None,
306
+ ) -> SourceRef:
307
+ source = _protocol_source(
308
+ method=method,
309
+ cursor=cursor,
310
+ thread_id=thread_id,
311
+ turn_id=turn_id,
312
+ native_item_id=native_item_id,
313
+ native_event_id=native_item_id,
314
+ )
315
+ return source.model_copy(
316
+ update={
317
+ "protocol": "a2ui",
318
+ "metadata": {
319
+ **source.metadata,
320
+ "surface_id": surface_id,
321
+ **dict(metadata or {}),
322
+ },
323
+ }
324
+ )
325
+
326
+ def _map_a2ui_surface(
327
+ self,
328
+ *,
329
+ params: Mapping[str, Any],
330
+ context: CodexAdapterContext,
331
+ cursor: str,
332
+ timestamp: float,
333
+ ) -> tuple[RuntimeEvent, ...]:
334
+ """Map one complete A2UI surface description as an immutable operation batch."""
335
+
336
+ surface_id = _required_string(params.get("surface_id"), "params.surface_id")
337
+ surface = _mapping(params.get("surface"), "params.surface")
338
+ thread_id, turn_id, scope_id = self._a2ui_scope(
339
+ params, context, surface_id=surface_id
340
+ )
341
+ item_id = stable_item_id("codex", scope_id, "a2ui-surface", surface_id)
342
+ source = self._a2ui_source(
343
+ method="a2ui/surface",
344
+ cursor=cursor,
345
+ thread_id=thread_id,
346
+ turn_id=turn_id,
347
+ native_item_id=surface_id,
348
+ surface_id=surface_id,
349
+ metadata={
350
+ "operation_batch": True,
351
+ "surface_lifecycle": "begin",
352
+ "catalog_id": str(surface.get("catalog_id") or surface.get("catalogId") or ""),
353
+ },
354
+ )
355
+ snapshot = ContentSnapshot(
356
+ parts=(
357
+ DataContent(
358
+ part_id="a2ui-surface",
359
+ data={"surface_id": surface_id, **_json_value(surface)},
360
+ ),
361
+ )
362
+ )
363
+ env = _envelope(context, cursor, timestamp)
364
+ return (
365
+ ItemStarted(
366
+ **env(scope_id, item_id, "item.started", "a2ui-surface", source),
367
+ item_id=item_id,
368
+ item_kind="data",
369
+ initial=snapshot,
370
+ ),
371
+ ItemCompleted(
372
+ **env(scope_id, item_id, "item.completed", "a2ui-surface", source),
373
+ item_id=item_id,
374
+ item_kind="data",
375
+ snapshot=snapshot,
376
+ ),
377
+ )
378
+
379
+ def _map_a2ui_interaction(
380
+ self,
381
+ *,
382
+ params: Mapping[str, Any],
383
+ context: CodexAdapterContext,
384
+ cursor: str,
385
+ timestamp: float,
386
+ ) -> tuple[RuntimeEvent, ...]:
387
+ """Map the client-owned A2UI input request without changing its live call id."""
388
+
389
+ surface_id = _required_string(params.get("surface_id"), "params.surface_id")
390
+ interaction_id = _required_string(
391
+ params.get("interaction_id"), "params.interaction_id"
392
+ )
393
+ kind = _required_string(params.get("kind"), "params.kind")
394
+ schema = _mapping(params.get("input_schema"), "params.input_schema")
395
+ is_blocking = params.get("is_blocking", True)
396
+ if not isinstance(is_blocking, bool):
397
+ _fail(
398
+ "invalid_interaction_request",
399
+ "params.is_blocking",
400
+ "A2UI is_blocking must be a boolean",
401
+ )
402
+ thread_id, turn_id, scope_id = self._a2ui_scope(
403
+ params, context, surface_id=surface_id
404
+ )
405
+ source = self._a2ui_source(
406
+ method="a2ui/interaction",
407
+ cursor=cursor,
408
+ thread_id=thread_id,
409
+ turn_id=turn_id,
410
+ native_item_id=interaction_id,
411
+ surface_id=surface_id,
412
+ metadata={"kind": kind, "is_blocking": is_blocking},
413
+ )
414
+ env = _envelope(context, cursor, timestamp)
415
+ requested = InteractionRequested(
416
+ **env(
417
+ scope_id,
418
+ interaction_id,
419
+ "interaction.requested",
420
+ "structured_input",
421
+ source,
422
+ ),
423
+ interaction_id=interaction_id,
424
+ interaction_kind="structured_input",
425
+ request=StructuredInputRequest(prompt=None, schema=_json_value(schema)),
426
+ )
427
+ if not is_blocking:
428
+ return (requested,)
429
+ return (
430
+ requested,
431
+ RunInterrupted(
432
+ **env(
433
+ scope_id,
434
+ turn_id,
435
+ "run.interrupted",
436
+ interaction_id,
437
+ source,
438
+ ),
439
+ status="interrupted",
440
+ reason="Codex requires user interaction",
441
+ interaction_id=interaction_id,
442
+ continuation_id=self._thread_continuations.setdefault(
443
+ thread_id, _thread_continuation_identity(thread_id)[1]
444
+ ),
445
+ ),
446
+ )
447
+
448
+ def _map_token_usage(
449
+ self,
450
+ *,
451
+ params: Mapping[str, Any],
452
+ context: CodexAdapterContext,
453
+ cursor: str,
454
+ timestamp: float,
455
+ ) -> tuple[RuntimeEvent, ...]:
456
+ """Project the current turn's exact App Server usage into the canonical event."""
457
+
458
+ thread_id = _required_string(params.get("threadId"), "params.threadId")
459
+ turn_id = _required_string(params.get("turnId"), "params.turnId")
460
+ usage_value = params.get("tokenUsage", params.get("token_usage"))
461
+ usage = _mapping(usage_value, "params.tokenUsage")
462
+ last = _mapping(usage.get("last"), "params.tokenUsage.last")
463
+
464
+ def metric(camel_name: str, snake_name: str) -> int:
465
+ value = last.get(camel_name, last.get(snake_name))
466
+ return _nonnegative_int(value, f"params.tokenUsage.last.{camel_name}")
467
+
468
+ input_tokens = metric("inputTokens", "input_tokens")
469
+ output_tokens = metric("outputTokens", "output_tokens")
470
+ total_tokens = metric("totalTokens", "total_tokens")
471
+ cached_tokens = metric("cachedInputTokens", "cached_input_tokens")
472
+ reasoning_tokens = metric("reasoningOutputTokens", "reasoning_output_tokens")
473
+ scope_id = stable_scope_id("codex", thread_id, turn_id)
474
+ source = _protocol_source(
475
+ method="thread/tokenUsage/updated",
476
+ cursor=cursor,
477
+ thread_id=thread_id,
478
+ turn_id=turn_id,
479
+ native_item_id=None,
480
+ )
481
+ env = _envelope(context, cursor, timestamp)
482
+ return (
483
+ UsageReported(
484
+ **env(scope_id, turn_id, "usage.reported", "usage", source),
485
+ input_tokens=input_tokens,
486
+ output_tokens=output_tokens,
487
+ total_tokens=total_tokens,
488
+ cached_tokens=cached_tokens,
489
+ reasoning_tokens=reasoning_tokens,
490
+ ),
491
+ )
492
+
493
+ def finish_stream(self) -> None:
494
+ """Fail closed if JSONL EOF leaves source-owned lifecycle state open."""
495
+
496
+ if not (
497
+ self._items
498
+ or self._active_turns
499
+ or self._interactions
500
+ or self._pending_resume_by_thread
501
+ ):
502
+ return
503
+ _fail(
504
+ "open_state_at_stream_end",
505
+ "jsonl eof",
506
+ "Codex JSONL ended with open items, turns, interactions, or resumes",
507
+ )
508
+
509
+ def _map_known_notification(
510
+ self,
511
+ *,
512
+ method: str,
513
+ params: Mapping[str, Any],
514
+ context: CodexAdapterContext,
515
+ cursor: str,
516
+ timestamp: float,
517
+ ) -> tuple[RuntimeEvent, ...]:
518
+ """Losslessly preserve legal 0.144.4 control notifications as typed data."""
519
+
520
+ thread_id_value = params.get("threadId")
521
+ turn_id_value = params.get("turnId")
522
+ thread_value = params.get("thread")
523
+ turn_value = params.get("turn")
524
+ if thread_id_value is None and isinstance(thread_value, Mapping):
525
+ thread_id_value = thread_value.get("id")
526
+ if turn_id_value is None and isinstance(turn_value, Mapping):
527
+ turn_id_value = turn_value.get("id")
528
+ thread_id = (
529
+ _required_string(thread_id_value, "params.threadId")
530
+ if thread_id_value is not None
531
+ else f"runtime:{context.run_id}"
532
+ )
533
+ turn_id = (
534
+ _required_string(turn_id_value, "params.turnId")
535
+ if turn_id_value is not None
536
+ else "control"
537
+ )
538
+ scope_id = stable_scope_id("codex", thread_id, turn_id)
539
+ state = _ItemState(
540
+ scope_id=scope_id,
541
+ thread_id=thread_id,
542
+ turn_id=turn_id,
543
+ native_item_id=f"{method}:{cursor}",
544
+ native_item_kind="notification",
545
+ item_id=stable_item_id("codex", scope_id, "notification", method, cursor),
546
+ item_kind="data",
547
+ phase="commentary",
548
+ )
549
+ source = _source(method, cursor, state)
550
+ part = DataContent(
551
+ part_id=_part_id(state, "notification", "params"),
552
+ data=_json_value(params),
553
+ )
554
+ env = _envelope(context, cursor, timestamp)
555
+ return (
556
+ ItemStarted(
557
+ **env(scope_id, state.item_id, "item.started", "notification", source),
558
+ item_id=state.item_id,
559
+ item_kind="data",
560
+ phase="commentary",
561
+ initial=None,
562
+ ),
563
+ ItemCompleted(
564
+ **env(scope_id, state.item_id, "item.completed", "snapshot", source),
565
+ item_id=state.item_id,
566
+ item_kind="data",
567
+ snapshot=ContentSnapshot(parts=(part,)),
568
+ ),
569
+ )
570
+
571
+ def _map_turn_event(
572
+ self,
573
+ *,
574
+ method: str,
575
+ params: Mapping[str, Any],
576
+ context: CodexAdapterContext,
577
+ cursor: str,
578
+ timestamp: float,
579
+ ) -> tuple[RuntimeEvent, ...]:
580
+ thread_id = _required_string(params.get("threadId"), "params.threadId")
581
+ turn = _mapping(params.get("turn"), "params.turn")
582
+ turn_id = _required_string(turn.get("id"), "params.turn.id")
583
+ status = _required_string(turn.get("status"), "params.turn.status")
584
+ scope_id = stable_scope_id("codex", thread_id, turn_id)
585
+ source = _protocol_source(
586
+ method=method,
587
+ cursor=cursor,
588
+ thread_id=thread_id,
589
+ turn_id=turn_id,
590
+ native_item_id=None,
591
+ )
592
+ env = _envelope(context, cursor, timestamp)
593
+
594
+ if method == "turn/started":
595
+ return self._map_turn_started(
596
+ env=env,
597
+ source=source,
598
+ thread_id=thread_id,
599
+ turn_id=turn_id,
600
+ scope_id=scope_id,
601
+ status=status,
602
+ cursor=cursor,
603
+ )
604
+
605
+ if scope_id not in self._active_turns:
606
+ _fail(
607
+ "turn_not_started",
608
+ "params.turn.id",
609
+ f"Codex turn {turn_id!r} completed before turn/started",
610
+ )
611
+ open_items = sorted(
612
+ state.native_item_id for state in self._items.values() if state.scope_id == scope_id
613
+ )
614
+ if open_items:
615
+ _fail(
616
+ "open_items_at_turn_end",
617
+ "item/completed",
618
+ f"Codex turn ended with open items: {open_items}",
619
+ )
620
+ output_refs = tuple(self._completed_items.get(scope_id, ()))
621
+ items = turn.get("items")
622
+ if not isinstance(items, Sequence) or isinstance(items, (str, bytes)):
623
+ _fail("invalid_turn_snapshot", "params.turn.items", "Codex turn items must be an array")
624
+
625
+ terminal: RuntimeEvent
626
+ if status == "completed":
627
+ terminal = RunCompleted(
628
+ **env(scope_id, turn_id, "run.completed", "run", source),
629
+ status="completed",
630
+ output_refs=output_refs,
631
+ )
632
+ elif status == "failed":
633
+ error = _mapping(turn.get("error"), "params.turn.error")
634
+ message = _required_text(error.get("message"), "params.turn.error.message")
635
+ terminal = RunFailed(
636
+ **env(scope_id, turn_id, "run.failed", "run", source),
637
+ status="failed",
638
+ error=ErrorInfo(
639
+ code="codex_turn_failed",
640
+ message=message,
641
+ source="codex",
642
+ scope_id=scope_id,
643
+ source_ref=source,
644
+ ),
645
+ )
646
+ elif status == "interrupted":
647
+ terminal = RunCanceled(
648
+ **env(scope_id, turn_id, "run.canceled", "run", source),
649
+ status="canceled",
650
+ reason="Codex turn/interrupt completed",
651
+ )
652
+ else:
653
+ _fail(
654
+ "invalid_turn_status",
655
+ "params.turn.status",
656
+ f"Unsupported terminal Codex turn status: {status}",
657
+ )
658
+ self._active_turns.remove(scope_id)
659
+ self._completed_items.pop(scope_id, None)
660
+ return (terminal,)
661
+
662
+ def _map_turn_started(
663
+ self,
664
+ *,
665
+ env: Callable[..., dict[str, Any]],
666
+ source: SourceRef,
667
+ thread_id: str,
668
+ turn_id: str,
669
+ scope_id: str,
670
+ status: str,
671
+ cursor: str,
672
+ ) -> tuple[RuntimeEvent, ...]:
673
+ if status != "inProgress":
674
+ _fail(
675
+ "invalid_turn_status",
676
+ "params.turn.status",
677
+ f"Codex turn/started requires inProgress, got: {status}",
678
+ )
679
+ if scope_id in self._active_turns:
680
+ _fail("turn_already_started", "params.turn.id", f"Codex turn {turn_id!r} started twice")
681
+ self._active_turns.add(scope_id)
682
+ run_started = RunStarted(
683
+ **env(scope_id, turn_id, "run.started", "run", source), status="running"
684
+ )
685
+ continuation_scope_id, derived_continuation_id = _thread_continuation_identity(thread_id)
686
+ continuation_existed = thread_id in self._thread_continuations
687
+ continuation_id = self._thread_continuations.setdefault(thread_id, derived_continuation_id)
688
+ resume_attempt = self._pending_resume_by_thread.pop(thread_id, None)
689
+ if resume_attempt is not None:
690
+ self._resume_requests.pop(resume_attempt, None)
691
+ continuation: RuntimeEvent = ContinuationResumed(
692
+ **env(
693
+ continuation_scope_id,
694
+ continuation_id,
695
+ "continuation.resumed",
696
+ "thread_resume",
697
+ source,
698
+ ),
699
+ continuation_id=continuation_id,
700
+ continuation_kind="thread_resume",
701
+ resume_attempt_id=resume_attempt,
702
+ )
703
+ elif not continuation_existed:
704
+ continuation = ContinuationCreated(
705
+ **env(
706
+ continuation_scope_id,
707
+ continuation_id,
708
+ "continuation.created",
709
+ "thread_resume",
710
+ source,
711
+ ),
712
+ continuation_id=continuation_id,
713
+ continuation_kind="thread_resume",
714
+ resumable=True,
715
+ ref={
716
+ "thread_id": thread_id,
717
+ "turn_id": turn_id,
718
+ "source_cursor": cursor,
719
+ },
720
+ )
721
+ else:
722
+ self._completed_items.setdefault(scope_id, [])
723
+ return (run_started,)
724
+ self._completed_items.setdefault(scope_id, [])
725
+ return (run_started, continuation)
726
+
727
+ def _map_error(
728
+ self,
729
+ params: Mapping[str, Any],
730
+ env: Callable[..., dict[str, Any]],
731
+ *,
732
+ scope_id: str,
733
+ thread_id: str,
734
+ turn_id: str,
735
+ cursor: str,
736
+ ) -> tuple[RuntimeEvent, ...]:
737
+ error = _mapping(params.get("error"), "params.error")
738
+ _required_text(error.get("message"), "params.error.message")
739
+ will_retry = params.get("willRetry")
740
+ if not isinstance(will_retry, bool):
741
+ _fail(
742
+ "invalid_protocol_message",
743
+ "params.willRetry",
744
+ "Codex params.willRetry must be a boolean",
745
+ )
746
+ base = _protocol_source(
747
+ method="error",
748
+ cursor=cursor,
749
+ thread_id=thread_id,
750
+ turn_id=turn_id,
751
+ native_item_id=None,
752
+ )
753
+ source = base.model_copy(
754
+ update={
755
+ "metadata": {
756
+ **base.metadata,
757
+ "will_retry": will_retry,
758
+ "error_message_present": True,
759
+ "additional_details_present": error.get("additionalDetails") is not None,
760
+ "codex_error_info_present": error.get("codexErrorInfo") is not None,
761
+ "codex_error_info_kind": _safe_codex_error_info_kind(
762
+ error.get("codexErrorInfo")
763
+ ),
764
+ }
765
+ }
766
+ )
767
+ return (
768
+ RunProgress(
769
+ **env(
770
+ scope_id,
771
+ turn_id,
772
+ "run.progress",
773
+ "retryable_error" if will_retry else "error_diagnostic",
774
+ source,
775
+ ),
776
+ status="running",
777
+ message=(
778
+ "Codex reported a retryable turn error"
779
+ if will_retry
780
+ else "Codex reported a non-retryable turn error"
781
+ ),
782
+ ),
783
+ )
784
+
785
+ def _map_item_started(
786
+ self,
787
+ params: Mapping[str, Any],
788
+ env: Callable[..., dict[str, Any]],
789
+ *,
790
+ scope_id: str,
791
+ thread_id: str,
792
+ turn_id: str,
793
+ cursor: str,
794
+ ) -> tuple[RuntimeEvent, ...]:
795
+ item = _mapping(params.get("item"), "params.item")
796
+ native_item_id = _required_string(item.get("id"), "params.item.id")
797
+ native_kind = _required_string(item.get("type"), "params.item.type")
798
+ state = _item_state(scope_id, thread_id, turn_id, native_item_id, native_kind, item)
799
+ key = (scope_id, native_item_id)
800
+ if key in self._items:
801
+ _fail(
802
+ "item_already_started",
803
+ "params.item.id",
804
+ f"Codex item {native_item_id!r} started twice",
805
+ )
806
+ self._items[key] = state
807
+ source = _source("item/started", cursor, state)
808
+ return (
809
+ ItemStarted(
810
+ **env(scope_id, state.item_id, "item.started", "item", source),
811
+ item_id=state.item_id,
812
+ item_kind=state.item_kind,
813
+ phase=state.phase,
814
+ initial=_initial_snapshot(state, item),
815
+ ),
816
+ )
817
+
818
+ def _map_item_updated(
819
+ self,
820
+ method: str,
821
+ params: Mapping[str, Any],
822
+ env: Callable[..., dict[str, Any]],
823
+ *,
824
+ scope_id: str,
825
+ cursor: str,
826
+ ) -> tuple[RuntimeEvent, ...]:
827
+ native_item_id = _required_string(params.get("itemId"), "params.itemId")
828
+ state = self._require_active_item(scope_id, native_item_id)
829
+ source = _source(method, cursor, state)
830
+ op, update = _item_update(method, params, state)
831
+ return (
832
+ ItemUpdated(
833
+ **env(scope_id, state.item_id, "item.updated", update.part_id, source),
834
+ item_id=state.item_id,
835
+ item_kind=state.item_kind,
836
+ op=op,
837
+ update=update,
838
+ ),
839
+ )
840
+
841
+ def _map_item_terminal(
842
+ self,
843
+ method: str,
844
+ params: Mapping[str, Any],
845
+ env: Callable[..., dict[str, Any]],
846
+ *,
847
+ scope_id: str,
848
+ cursor: str,
849
+ ) -> tuple[RuntimeEvent, ...]:
850
+ item = _mapping(params.get("item"), "params.item")
851
+ native_item_id = _required_string(item.get("id"), "params.itemId")
852
+ state = self._require_active_item(scope_id, native_item_id)
853
+ source = _source(method, cursor, state)
854
+ native_kind = _required_string(item.get("type"), "params.item.type")
855
+ if native_kind != state.native_item_kind:
856
+ _fail(
857
+ "conflicting_item_kind",
858
+ "params.item.type",
859
+ "Codex item changed type during its lifecycle",
860
+ )
861
+ snapshot = _completed_snapshot(state, item)
862
+ del self._items[(scope_id, native_item_id)]
863
+ if _item_failed(state, item):
864
+ correction = snapshot.parts[-1]
865
+ corrected = ItemUpdated(
866
+ **env(scope_id, state.item_id, "item.updated", correction.part_id, source),
867
+ item_id=state.item_id,
868
+ item_kind=state.item_kind,
869
+ op="replace",
870
+ update=correction,
871
+ )
872
+ failed = ItemFailed(
873
+ **env(scope_id, state.item_id, "item.failed", "failure", source),
874
+ item_id=state.item_id,
875
+ item_kind=state.item_kind,
876
+ error=ErrorInfo(
877
+ code=f"codex_{_FAILURE_CODE_KINDS.get(state.native_item_kind, 'item')}_failed",
878
+ message=f"Codex {state.native_item_kind} failed",
879
+ source="codex",
880
+ scope_id=scope_id,
881
+ item_id=state.item_id,
882
+ source_ref=source,
883
+ ),
884
+ )
885
+ return (corrected, failed)
886
+ if state.phase == "final_answer":
887
+ self._completed_items.setdefault(scope_id, []).append(
888
+ OutputRef(scope_id=scope_id, item_id=state.item_id)
889
+ )
890
+ return (
891
+ ItemCompleted(
892
+ **env(scope_id, state.item_id, "item.completed", "snapshot", source),
893
+ item_id=state.item_id,
894
+ item_kind=state.item_kind,
895
+ snapshot=snapshot,
896
+ ),
897
+ )
898
+
899
+ def _require_active_item(self, scope_id: str, native_item_id: str) -> _ItemState:
900
+ state = self._items.get((scope_id, native_item_id))
901
+ if state is None:
902
+ _fail(
903
+ "item_not_started",
904
+ "params.itemId",
905
+ f"Codex item {native_item_id!r} mutated before item/started",
906
+ )
907
+ return state