agentengine-sdk-python 0.6.9__py3-none-any.whl → 0.7.0__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 (149) hide show
  1. {agentengine_sdk_python-0.6.9.dist-info → agentengine_sdk_python-0.7.0.dist-info}/METADATA +6 -4
  2. {agentengine_sdk_python-0.6.9.dist-info → agentengine_sdk_python-0.7.0.dist-info}/RECORD +123 -128
  3. ksadk/api/client.py +19 -0
  4. ksadk/cli/cmd_create.py +34 -7
  5. ksadk/cli/cmd_hermes.py +6 -2
  6. ksadk/cli/cmd_invoke.py +208 -41
  7. ksadk/cli/cmd_mcp.py +6 -1
  8. ksadk/cli/cmd_openclaw.py +6 -2
  9. ksadk/cli/cmd_run.py +13 -6
  10. ksadk/cli/network_options.py +5 -3
  11. ksadk/configs/env_registry.py +1 -0
  12. ksadk/conversations/message_projection.py +269 -0
  13. ksadk/conversations/model_context.py +11 -1
  14. ksadk/conversations/runtime.py +81 -13
  15. ksadk/deployment/base.py +1 -1
  16. ksadk/deployment/providers/serverless.py +18 -8
  17. ksadk/memory/adk/resilient_session_service.py +268 -0
  18. ksadk/memory/adk/short_term_memory.py +21 -6
  19. ksadk/runners/adk_runner.py +974 -115
  20. ksadk/runners/langchain_runner.py +219 -7
  21. ksadk/runners/langgraph_runner.py +145 -12
  22. ksadk/runners/remote_runner.py +143 -18
  23. ksadk/server/app.py +148 -6
  24. ksadk/server/static/assets/{ArtifactsPanel-C0meuOdi.js → ArtifactsPanel-D-SSn2ee.js} +1 -1
  25. ksadk/server/static/assets/{CodeBlock-BbI4HPtJ.js → CodeBlock-P16VOLYi.js} +1 -1
  26. ksadk/server/static/assets/{MathMessageMarkdown-DMLQYoLp.js → MathMessageMarkdown-CdGiQWHR.js} +1 -1
  27. ksadk/server/static/assets/{MermaidBlock-DCR8WZ17.js → MermaidBlock-IOcal8cm.js} +6 -6
  28. ksadk/server/static/assets/{NativeTerminalPanel-CKUvWhUz.js → NativeTerminalPanel-DGSDWsei.js} +1 -1
  29. ksadk/server/static/assets/{arc-bj2rZnP5.js → arc-BA13sHc9.js} +1 -1
  30. ksadk/server/static/assets/architecture-7EHR7CIX-BvUlsA6l.js +1 -0
  31. ksadk/server/static/assets/{architectureDiagram-3BPJPVTR-2u1ltDIj.js → architectureDiagram-3BPJPVTR-DzJzgVoL.js} +1 -1
  32. ksadk/server/static/assets/{blockDiagram-GPEHLZMM-D6fvdK20.js → blockDiagram-GPEHLZMM-UTdVcZhn.js} +1 -1
  33. ksadk/server/static/assets/{c4Diagram-AAUBKEIU-BK82L5n5.js → c4Diagram-AAUBKEIU-Dix0GD4m.js} +1 -1
  34. ksadk/server/static/assets/channel-CTuydARX.js +1 -0
  35. ksadk/server/static/assets/{chunk-2J33WTMH-DLVdkeyQ.js → chunk-2J33WTMH-C2JxuZ42.js} +1 -1
  36. ksadk/server/static/assets/{chunk-4BX2VUAB-BbwsYcbW.js → chunk-4BX2VUAB-Be57QPgD.js} +1 -1
  37. ksadk/server/static/assets/{chunk-55IACEB6-DOairxzw.js → chunk-55IACEB6-WjSuy4nv.js} +1 -1
  38. ksadk/server/static/assets/{chunk-727SXJPM-hCO487gs.js → chunk-727SXJPM-BOovP-b5.js} +1 -1
  39. ksadk/server/static/assets/{chunk-AQP2D5EJ-XU8vDOuG.js → chunk-AQP2D5EJ-DOmZNmWj.js} +1 -1
  40. ksadk/server/static/assets/{chunk-FMBD7UC4-PrapyfMu.js → chunk-FMBD7UC4-DzwlodkU.js} +1 -1
  41. ksadk/server/static/assets/{chunk-ND2GUHAM-CboKhTZ3.js → chunk-ND2GUHAM-DMqAikEU.js} +1 -1
  42. ksadk/server/static/assets/chunk-QZHKN3VN-BnCydivS.js +1 -0
  43. ksadk/server/static/assets/classDiagram-4FO5ZUOK-BNHg45Be.js +1 -0
  44. ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-BNHg45Be.js +1 -0
  45. ksadk/server/static/assets/{cose-bilkent-S5V4N54A-_N8bJ-EU.js → cose-bilkent-S5V4N54A-Zhy2GBnP.js} +1 -1
  46. ksadk/server/static/assets/{dagre-BM42HDAG-FoDlo5J2.js → dagre-BM42HDAG-CbKrtIUz.js} +1 -1
  47. ksadk/server/static/assets/{diagram-2AECGRRQ-BBp6ebBw.js → diagram-2AECGRRQ-BRApgQRK.js} +1 -1
  48. ksadk/server/static/assets/{diagram-5GNKFQAL-CqOvG1PR.js → diagram-5GNKFQAL-D0xbnDiK.js} +1 -1
  49. ksadk/server/static/assets/{diagram-KO2AKTUF-O9T3t6ba.js → diagram-KO2AKTUF-CVugVI9L.js} +1 -1
  50. ksadk/server/static/assets/{diagram-LMA3HP47-CGG8ekBO.js → diagram-LMA3HP47-DozUGgee.js} +1 -1
  51. ksadk/server/static/assets/{diagram-OG6HWLK6-4BmH1EEg.js → diagram-OG6HWLK6-ZOYsKlru.js} +1 -1
  52. ksadk/server/static/assets/{dist-BmuTWcm7.js → dist-2hInLS_J.js} +1 -1
  53. ksadk/server/static/assets/{dist-BMKM66B4.js → dist-8EEyGgDx.js} +1 -1
  54. ksadk/server/static/assets/{dist-Cp1_jKwf.js → dist-8_SfK1IP.js} +1 -1
  55. ksadk/server/static/assets/{dist-CZ6C3x8B.js → dist-B0NP_Z0z.js} +1 -1
  56. ksadk/server/static/assets/{dist-DLeM1OCK.js → dist-BIJVDMuB.js} +1 -1
  57. ksadk/server/static/assets/{dist-Cwhk4lwI.js → dist-BmlMPsCc.js} +1 -1
  58. ksadk/server/static/assets/{dist-D99wf6_X.js → dist-BrCcQ47T.js} +1 -1
  59. ksadk/server/static/assets/{dist-CWiTDN_V.js → dist-BssVmjIo.js} +1 -1
  60. ksadk/server/static/assets/{dist-BVzcWa6D.js → dist-C3HIIaN5.js} +1 -1
  61. ksadk/server/static/assets/{dist-DM0rEQPk.js → dist-CPBtqRTW.js} +1 -1
  62. ksadk/server/static/assets/{dist-BkJjNih3.js → dist-CkEKJFtk.js} +1 -1
  63. ksadk/server/static/assets/{dist-B67uF2uK.js → dist-D-JMdWPQ.js} +1 -1
  64. ksadk/server/static/assets/{dist-DI-oVAXw.js → dist-D-xOD048.js} +1 -1
  65. ksadk/server/static/assets/{dist-6kSZvCZh.js → dist-D57wnGWd.js} +1 -1
  66. ksadk/server/static/assets/{dist-Bk1l05Ni.js → dist-DL_NKc_z.js} +1 -1
  67. ksadk/server/static/assets/{dist-DbaH3p5h.js → dist-DMezvBGJ.js} +1 -1
  68. ksadk/server/static/assets/{dist-CiZHB6ZW.js → dist-DmFaq_Iy.js} +1 -1
  69. ksadk/server/static/assets/{dist-DLMjL01k.js → dist-Dp0k7bWI.js} +1 -1
  70. ksadk/server/static/assets/{dist-DCpZrjaK.js → dist-DpKtt4Bo.js} +1 -1
  71. ksadk/server/static/assets/{dist-D5JGcxBx.js → dist-DyOkZmze.js} +1 -1
  72. ksadk/server/static/assets/{dist-C2DKRFVK.js → dist-DyWsb78Q.js} +1 -1
  73. ksadk/server/static/assets/{dist-S4klkK5W.js → dist-gX6GOLKq.js} +1 -1
  74. ksadk/server/static/assets/{erDiagram-TEJ5UH35-oJhaci7S.js → erDiagram-TEJ5UH35-Bk-9bgE5.js} +1 -1
  75. ksadk/server/static/assets/eventmodeling-FCH6USID-DsAgWnlf.js +1 -0
  76. ksadk/server/static/assets/{flowDiagram-I6XJVG4X-DtTmUan-.js → flowDiagram-I6XJVG4X-Dn9kZVuZ.js} +1 -1
  77. ksadk/server/static/assets/{ganttDiagram-6RSMTGT7-BSsb_eij.js → ganttDiagram-6RSMTGT7-BGxXlJqm.js} +1 -1
  78. ksadk/server/static/assets/gitGraph-WXDBUCRP-BIao9Yjg.js +1 -0
  79. ksadk/server/static/assets/{gitGraphDiagram-PVQCEYII-BR5s6Pws.js → gitGraphDiagram-PVQCEYII-C7Q0X-wi.js} +1 -1
  80. ksadk/server/static/assets/{index-BH7-pC0B.js → index-C00Lwg3L.js} +6 -6
  81. ksadk/server/static/assets/info-J43DQDTF-CyipqGxU.js +1 -0
  82. ksadk/server/static/assets/{infoDiagram-5YYISTIA-DYPc5cvh.js → infoDiagram-5YYISTIA-BO_CSqq5.js} +1 -1
  83. ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-MoBdALDg.js → ishikawaDiagram-YF4QCWOH-eYLPLd46.js} +1 -1
  84. ksadk/server/static/assets/{journeyDiagram-JHISSGLW-DgLiQT8l.js → journeyDiagram-JHISSGLW-De9geSb0.js} +1 -1
  85. ksadk/server/static/assets/{kanban-definition-UN3LZRKU-CsFx112F.js → kanban-definition-UN3LZRKU-Cs80kQto.js} +1 -1
  86. ksadk/server/static/assets/{katex-DRsiwpM2.js → katex-DSrCFD8n.js} +1 -1
  87. ksadk/server/static/assets/{linear-TNRQ5Orv.js → linear-CN9sbKTF.js} +1 -1
  88. ksadk/server/static/assets/{mermaid-parser.core-D2eMVOgo.js → mermaid-parser.core-DlgSBU8l.js} +2 -2
  89. ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-BtByYFhL.js → mindmap-definition-RKZ34NQL-9afz7Oug.js} +1 -1
  90. ksadk/server/static/assets/packet-YPE3B663-CGkyRxlg.js +1 -0
  91. ksadk/server/static/assets/pie-LRSECV5Y-M0uWAf4n.js +1 -0
  92. ksadk/server/static/assets/{pieDiagram-4H26LBE5-DPnuCB8c.js → pieDiagram-4H26LBE5-DPv_VstN.js} +1 -1
  93. ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-miFpCPv4.js → quadrantDiagram-W4KKPZXB-o77wZ1XK.js} +1 -1
  94. ksadk/server/static/assets/radar-GUYGQ44K-Bdbm24-x.js +1 -0
  95. ksadk/server/static/assets/{requirementDiagram-4Y6WPE33-mjB_yYkW.js → requirementDiagram-4Y6WPE33-BYVw81VC.js} +1 -1
  96. ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-D7hSlZZZ.js → sankeyDiagram-5OEKKPKP-B7nZFMKT.js} +1 -1
  97. ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-D9Cx6hC3.js → sequenceDiagram-3UESZ5HK-BGRRrFw5.js} +1 -1
  98. ksadk/server/static/assets/{stateDiagram-AJRCARHV-D_zrg47o.js → stateDiagram-AJRCARHV-BUfHCoPs.js} +1 -1
  99. ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-8xBN_gLM.js +1 -0
  100. ksadk/server/static/assets/{timeline-definition-PNZ67QCA-CwSec0Wa.js → timeline-definition-PNZ67QCA-FbCTGrf9.js} +1 -1
  101. ksadk/server/static/assets/treeView-BLDUP644-npMo0ak1.js +1 -0
  102. ksadk/server/static/assets/treemap-LRROVOQU-CHdzrrdo.js +1 -0
  103. ksadk/server/static/assets/{vennDiagram-CIIHVFJN-agCVobiF.js → vennDiagram-CIIHVFJN-DWgwtPsJ.js} +1 -1
  104. ksadk/server/static/assets/wardley-L42UT6IY-BEQz7wyy.js +1 -0
  105. ksadk/server/static/assets/{wardleyDiagram-YWT4CUSO-TmrlhWNt.js → wardleyDiagram-YWT4CUSO-2x8G-tTM.js} +1 -1
  106. ksadk/server/static/assets/{xychartDiagram-2RQKCTM6-DV71V-ah.js → xychartDiagram-2RQKCTM6-Drma3AYl.js} +1 -1
  107. ksadk/server/static/index.html +1 -1
  108. ksadk/sessions/__init__.py +17 -21
  109. ksadk/sessions/continuity.py +28 -4
  110. ksadk/sessions/postgres_service.py +77 -14
  111. ksadk/sessions/resilience.py +52 -0
  112. ksadk/sessions/resilient.py +360 -0
  113. ksadk/toolsets/__init__.py +2 -0
  114. ksadk/toolsets/workspace.py +49 -10
  115. ksadk/tracing/setup.py +63 -0
  116. ksadk/tui/__init__.py +22 -7
  117. ksadk/tui/loop.py +1877 -0
  118. ksadk/tui/stream_render.py +68 -0
  119. ksadk/version.py +1 -1
  120. ksadk/server/static/assets/architecture-7EHR7CIX-Cr6Xz1_c.js +0 -1
  121. ksadk/server/static/assets/channel-BSSOwFIb.js +0 -1
  122. ksadk/server/static/assets/chunk-QZHKN3VN-XXpdiwUL.js +0 -1
  123. ksadk/server/static/assets/classDiagram-4FO5ZUOK-C5HvGiyK.js +0 -1
  124. ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-C5HvGiyK.js +0 -1
  125. ksadk/server/static/assets/eventmodeling-FCH6USID-CIgwHJLL.js +0 -1
  126. ksadk/server/static/assets/gitGraph-WXDBUCRP-BVAJ7uo0.js +0 -1
  127. ksadk/server/static/assets/info-J43DQDTF-MT80V4ge.js +0 -1
  128. ksadk/server/static/assets/packet-YPE3B663-BLKhbXZB.js +0 -1
  129. ksadk/server/static/assets/pie-LRSECV5Y-DFOikjSY.js +0 -1
  130. ksadk/server/static/assets/radar-GUYGQ44K-095b1Ikw.js +0 -1
  131. ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-J9kCb0nC.js +0 -1
  132. ksadk/server/static/assets/treeView-BLDUP644-yinfJEY6.js +0 -1
  133. ksadk/server/static/assets/treemap-LRROVOQU-DosUqN1Q.js +0 -1
  134. ksadk/server/static/assets/wardley-L42UT6IY-Bvp7-5uH.js +0 -1
  135. ksadk/tui/app.py +0 -400
  136. ksadk/tui/clipboard.py +0 -100
  137. ksadk/tui/widgets/__init__.py +0 -22
  138. ksadk/tui/widgets/assistant.py +0 -89
  139. ksadk/tui/widgets/base.py +0 -54
  140. ksadk/tui/widgets/chat_input.py +0 -246
  141. ksadk/tui/widgets/history.py +0 -156
  142. ksadk/tui/widgets/system.py +0 -87
  143. ksadk/tui/widgets/thinking.py +0 -110
  144. ksadk/tui/widgets/tool_call.py +0 -161
  145. ksadk/tui/widgets/user.py +0 -37
  146. {agentengine_sdk_python-0.6.9.dist-info → agentengine_sdk_python-0.7.0.dist-info}/WHEEL +0 -0
  147. {agentengine_sdk_python-0.6.9.dist-info → agentengine_sdk_python-0.7.0.dist-info}/entry_points.txt +0 -0
  148. {agentengine_sdk_python-0.6.9.dist-info → agentengine_sdk_python-0.7.0.dist-info}/licenses/LICENSE +0 -0
  149. {agentengine_sdk_python-0.6.9.dist-info → agentengine_sdk_python-0.7.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- import{t as e}from"./mermaid-parser.core-D2eMVOgo.js";import{t}from"./chunk-4BX2VUAB-BbwsYcbW.js";import{An as n,Jt as r,N as i,Zt as a,_n as o,en as s,hn as c,in as l,kn as u,mn as d,mt as f,nn as p,on as m,rn as h,tn as g}from"./MermaidBlock-DCR8WZ17.js";var _=u((e,t)=>{let n=e<=1?e*100:e;if(n<0||n>100)throw Error(`${t} must be between 0-1 (decimal) or 0-100 (percentage). Received: ${e}`);return n},`toPercent`),v=u((e,t,n)=>({x:_(t,`${n} evolution`),y:_(e,`${n} visibility`)}),`toCoordinates`),y=u(e=>{if(e){if(e===`+<>`)return`bidirectional`;if(e===`+<`)return`backward`;if(e===`+>`)return`forward`}},`getFlowFromPort`),b=u(e=>{if(!e?.startsWith(`+`))return{};let t=/^\+'([^']*)'/.exec(e)?.[1];return e.includes(`<>`)?{flow:`bidirectional`,label:t}:e.includes(`<`)?{flow:`backward`,label:t}:e.includes(`>`)?{flow:`forward`,label:t}:{label:t}},`extractFlowFromArrow`),x=u((e,n)=>{if(t(e,n),e.size&&n.setSize(e.size.width,e.size.height),e.evolution){let t=e.evolution.stages.map(e=>e.secondName?`${e.name.trim()} / ${e.secondName.trim()}`:e.name.trim()),r=e.evolution.stages.filter(e=>e.boundary!==void 0).map(e=>e.boundary);n.updateAxes({stages:t,stageBoundaries:r})}if(e.anchors.forEach(e=>{let t=v(e.visibility,e.evolution,`Anchor "${e.name}"`);n.addNode(e.name,e.name,t.x,t.y,`anchor`)}),e.components.forEach(e=>{let t=v(e.visibility,e.evolution,`Component "${e.name}"`),r=e.label?(e.label.negX?-1:1)*e.label.offsetX:void 0,i=e.label?(e.label.negY?-1:1)*e.label.offsetY:void 0,a=e.decorator?.strategy;n.addNode(e.name,e.name,t.x,t.y,`component`,r,i,e.inertia,a)}),e.notes.forEach(e=>{let t=v(e.visibility,e.evolution,`Note "${e.text}"`);n.addNote(e.text,t.x,t.y)}),e.pipelines.forEach(e=>{let t=n.getNode(e.parent);if(!t||typeof t.y!=`number`)throw Error(`Pipeline "${e.parent}" must reference an existing component with coordinates.`);let r=t.y;n.startPipeline(e.parent),e.components.forEach(t=>{let i=`${e.parent}_${t.name}`,a=t.label?(t.label.negX?-1:1)*t.label.offsetX:void 0,o=t.label?(t.label.negY?-1:1)*t.label.offsetY:void 0,s=_(t.evolution,`Pipeline component "${t.name}" evolution`);n.addNode(i,t.name,s,r,`pipeline-component`,a,o),n.addPipelineComponent(e.parent,i)})}),e.links.forEach(e=>{let t=!!e.arrow&&(e.arrow.includes(`-.->`)||e.arrow.includes(`.-.`)),r=y(e.fromPort)??y(e.toPort),{flow:i,label:a}=b(e.arrow);!r&&i&&(r=i);let o=e.linkLabel,s=a??o;n.addLink(n.resolveNodeId(e.from),n.resolveNodeId(e.to),t,s,r)}),e.evolves.forEach(e=>{let t=n.getNode(e.component);if(t?.y!==void 0){let r=_(e.target,`Evolve target for "${e.component}"`);n.addTrend(e.component,r,t.y)}}),e.annotations.length>0){let t=e.annotations[0],r=v(t.x,t.y,`Annotations box`);n.setAnnotationsBox(r.x,r.y)}e.annotation.forEach(e=>{let t=v(e.x,e.y,`Annotation ${e.number}`);n.addAnnotation(e.number,[{x:t.x,y:t.y}],e.text)}),e.accelerators.forEach(e=>{let t=v(e.x,e.y,`Accelerator "${e.name}"`);n.addAccelerator(e.name,t.x,t.y)}),e.deaccelerators.forEach(e=>{let t=v(e.x,e.y,`Deaccelerator "${e.name}"`);n.addDeaccelerator(e.name,t.x,t.y)})},`populateDb`),S={parser:{yy:void 0},parse:u(async t=>{let r=await e(`wardley`,t);n.debug(r);let i=S.parser?.yy;if(!i||typeof i.addNode!=`function`)throw Error(`parser.parser?.yy was not a WardleyDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.`);x(r,i)},`parse`)},C=new class{constructor(){this.nodes=new Map,this.links=[],this.trends=new Map,this.pipelines=new Map,this.annotations=[],this.notes=[],this.accelerators=[],this.deaccelerators=[],this.axes={}}static{u(this,`WardleyBuilder`)}addNode(e){let t=this.nodes.get(e.id)??{id:e.id,label:e.label},n={...t,...e,className:e.className??t.className,labelOffsetX:e.labelOffsetX??t.labelOffsetX,labelOffsetY:e.labelOffsetY??t.labelOffsetY};this.nodes.set(e.id,n)}addLink(e){this.links.push(e)}addTrend(e){this.trends.set(e.nodeId,e)}startPipeline(e){this.pipelines.set(e,{nodeId:e,componentIds:[]});let t=this.nodes.get(e);t&&(t.isPipelineParent=!0)}addPipelineComponent(e,t){let n=this.pipelines.get(e);n&&n.componentIds.push(t);let r=this.nodes.get(t);r&&(r.inPipeline=!0)}addAnnotation(e){this.annotations.push(e)}addNote(e){this.notes.push(e)}addAccelerator(e){this.accelerators.push(e)}addDeaccelerator(e){this.deaccelerators.push(e)}setAnnotationsBox(e,t){this.annotationsBox={x:e,y:t}}setAxes(e){this.axes={...this.axes,...e}}setSize(e,t){this.size={width:e,height:t}}getNode(e){return this.nodes.get(e)}resolveNodeId(e){if(this.nodes.has(e))return e;for(let[t,n]of this.nodes)if(n.label===e)return t;return e}build(){let e=[];for(let t of this.nodes.values()){if(typeof t.x!=`number`||typeof t.y!=`number`)throw Error(`Node "${t.label}" is missing coordinates`);e.push(t)}return{nodes:e,links:[...this.links],trends:[...this.trends.values()],pipelines:[...this.pipelines.values()],annotations:[...this.annotations],notes:[...this.notes],accelerators:[...this.accelerators],deaccelerators:[...this.deaccelerators],annotationsBox:this.annotationsBox,axes:{...this.axes},size:this.size}}clear(){this.nodes.clear(),this.links=[],this.trends.clear(),this.pipelines.clear(),this.annotations=[],this.notes=[],this.accelerators=[],this.deaccelerators=[],this.annotationsBox=void 0,this.axes={},this.size=void 0}};function w(){return h()[`wardley-beta`]}u(w,`getConfig`);function T(e,t,n,r,i,a,o,s,c){C.addNode({id:e,label:t,x:n,y:r,className:i,labelOffsetX:a,labelOffsetY:o,inertia:s,sourceStrategy:c})}u(T,`addNode`);function E(e,t,n=!1,r,i){C.addLink({source:e,target:t,dashed:n,label:r,flow:i})}u(E,`addLink`);function D(e,t,n){C.addTrend({nodeId:e,targetX:t,targetY:n})}u(D,`addTrend`);function O(e,t,n){C.addAnnotation({number:e,coordinates:t,text:n})}u(O,`addAnnotation`);function k(e,t,n){C.addNote({text:e,x:t,y:n})}u(k,`addNote`);function A(e,t,n){C.addAccelerator({name:e,x:t,y:n})}u(A,`addAccelerator`);function j(e,t,n){C.addDeaccelerator({name:e,x:t,y:n})}u(j,`addDeaccelerator`);function M(e,t){C.setAnnotationsBox(e,t)}u(M,`setAnnotationsBox`);function N(e,t){C.setSize(e,t)}u(N,`setSize`);function P(e){C.startPipeline(e)}u(P,`startPipeline`);function F(e,t){C.addPipelineComponent(e,t)}u(F,`addPipelineComponent`);function I(e){C.setAxes(e)}u(I,`updateAxes`);function L(e){return C.getNode(e)}u(L,`getNode`);function R(e){return C.resolveNodeId(e)}u(R,`resolveNodeId`);function z(){return C.build()}u(z,`getWardleyData`);function B(){C.clear(),r()}u(B,`clear`);var V={getConfig:w,addNode:T,addLink:E,addTrend:D,addAnnotation:O,addNote:k,addAccelerator:A,addDeaccelerator:j,setAnnotationsBox:M,setSize:N,startPipeline:P,addPipelineComponent:F,updateAxes:I,getNode:L,resolveNodeId:R,getWardleyData:z,clear:B,setAccTitle:c,getAccTitle:g,setDiagramTitle:o,getDiagramTitle:l,getAccDescription:s,setAccDescription:d},H=[`Genesis`,`Custom Built`,`Product`,`Commodity`],U=u(()=>{let{themeVariables:e}=h();return{backgroundColor:e.wardley?.backgroundColor??e.background??`#fff`,axisColor:e.wardley?.axisColor??`#000`,axisTextColor:e.wardley?.axisTextColor??e.primaryTextColor??`#222`,gridColor:e.wardley?.gridColor??`rgba(100, 100, 100, 0.2)`,componentFill:e.wardley?.componentFill??`#fff`,componentStroke:e.wardley?.componentStroke??`#000`,componentLabelColor:e.wardley?.componentLabelColor??e.primaryTextColor??`#222`,linkStroke:e.wardley?.linkStroke??`#000`,evolutionStroke:e.wardley?.evolutionStroke??`#dc3545`,annotationStroke:e.wardley?.annotationStroke??`#000`,annotationTextColor:e.wardley?.annotationTextColor??e.primaryTextColor??`#222`,annotationFill:e.wardley?.annotationFill??e.background??`#fff`}},`getTheme`),W=u(()=>{let e=h()[`wardley-beta`];return{width:e?.width??900,height:e?.height??600,padding:e?.padding??48,nodeRadius:e?.nodeRadius??6,nodeLabelOffset:e?.nodeLabelOffset??8,axisFontSize:e?.axisFontSize??12,labelFontSize:e?.labelFontSize??10,showGrid:e?.showGrid??!1,useMaxWidth:e?.useMaxWidth??!0}},`getConfigValues`),G={parser:S,db:V,renderer:{draw:u((e,t,r,i)=>{n.debug(`Rendering Wardley map
1
+ import{t as e}from"./mermaid-parser.core-DlgSBU8l.js";import{t}from"./chunk-4BX2VUAB-Be57QPgD.js";import{An as n,Jt as r,N as i,Zt as a,_n as o,en as s,hn as c,in as l,kn as u,mn as d,mt as f,nn as p,on as m,rn as h,tn as g}from"./MermaidBlock-IOcal8cm.js";var _=u((e,t)=>{let n=e<=1?e*100:e;if(n<0||n>100)throw Error(`${t} must be between 0-1 (decimal) or 0-100 (percentage). Received: ${e}`);return n},`toPercent`),v=u((e,t,n)=>({x:_(t,`${n} evolution`),y:_(e,`${n} visibility`)}),`toCoordinates`),y=u(e=>{if(e){if(e===`+<>`)return`bidirectional`;if(e===`+<`)return`backward`;if(e===`+>`)return`forward`}},`getFlowFromPort`),b=u(e=>{if(!e?.startsWith(`+`))return{};let t=/^\+'([^']*)'/.exec(e)?.[1];return e.includes(`<>`)?{flow:`bidirectional`,label:t}:e.includes(`<`)?{flow:`backward`,label:t}:e.includes(`>`)?{flow:`forward`,label:t}:{label:t}},`extractFlowFromArrow`),x=u((e,n)=>{if(t(e,n),e.size&&n.setSize(e.size.width,e.size.height),e.evolution){let t=e.evolution.stages.map(e=>e.secondName?`${e.name.trim()} / ${e.secondName.trim()}`:e.name.trim()),r=e.evolution.stages.filter(e=>e.boundary!==void 0).map(e=>e.boundary);n.updateAxes({stages:t,stageBoundaries:r})}if(e.anchors.forEach(e=>{let t=v(e.visibility,e.evolution,`Anchor "${e.name}"`);n.addNode(e.name,e.name,t.x,t.y,`anchor`)}),e.components.forEach(e=>{let t=v(e.visibility,e.evolution,`Component "${e.name}"`),r=e.label?(e.label.negX?-1:1)*e.label.offsetX:void 0,i=e.label?(e.label.negY?-1:1)*e.label.offsetY:void 0,a=e.decorator?.strategy;n.addNode(e.name,e.name,t.x,t.y,`component`,r,i,e.inertia,a)}),e.notes.forEach(e=>{let t=v(e.visibility,e.evolution,`Note "${e.text}"`);n.addNote(e.text,t.x,t.y)}),e.pipelines.forEach(e=>{let t=n.getNode(e.parent);if(!t||typeof t.y!=`number`)throw Error(`Pipeline "${e.parent}" must reference an existing component with coordinates.`);let r=t.y;n.startPipeline(e.parent),e.components.forEach(t=>{let i=`${e.parent}_${t.name}`,a=t.label?(t.label.negX?-1:1)*t.label.offsetX:void 0,o=t.label?(t.label.negY?-1:1)*t.label.offsetY:void 0,s=_(t.evolution,`Pipeline component "${t.name}" evolution`);n.addNode(i,t.name,s,r,`pipeline-component`,a,o),n.addPipelineComponent(e.parent,i)})}),e.links.forEach(e=>{let t=!!e.arrow&&(e.arrow.includes(`-.->`)||e.arrow.includes(`.-.`)),r=y(e.fromPort)??y(e.toPort),{flow:i,label:a}=b(e.arrow);!r&&i&&(r=i);let o=e.linkLabel,s=a??o;n.addLink(n.resolveNodeId(e.from),n.resolveNodeId(e.to),t,s,r)}),e.evolves.forEach(e=>{let t=n.getNode(e.component);if(t?.y!==void 0){let r=_(e.target,`Evolve target for "${e.component}"`);n.addTrend(e.component,r,t.y)}}),e.annotations.length>0){let t=e.annotations[0],r=v(t.x,t.y,`Annotations box`);n.setAnnotationsBox(r.x,r.y)}e.annotation.forEach(e=>{let t=v(e.x,e.y,`Annotation ${e.number}`);n.addAnnotation(e.number,[{x:t.x,y:t.y}],e.text)}),e.accelerators.forEach(e=>{let t=v(e.x,e.y,`Accelerator "${e.name}"`);n.addAccelerator(e.name,t.x,t.y)}),e.deaccelerators.forEach(e=>{let t=v(e.x,e.y,`Deaccelerator "${e.name}"`);n.addDeaccelerator(e.name,t.x,t.y)})},`populateDb`),S={parser:{yy:void 0},parse:u(async t=>{let r=await e(`wardley`,t);n.debug(r);let i=S.parser?.yy;if(!i||typeof i.addNode!=`function`)throw Error(`parser.parser?.yy was not a WardleyDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.`);x(r,i)},`parse`)},C=new class{constructor(){this.nodes=new Map,this.links=[],this.trends=new Map,this.pipelines=new Map,this.annotations=[],this.notes=[],this.accelerators=[],this.deaccelerators=[],this.axes={}}static{u(this,`WardleyBuilder`)}addNode(e){let t=this.nodes.get(e.id)??{id:e.id,label:e.label},n={...t,...e,className:e.className??t.className,labelOffsetX:e.labelOffsetX??t.labelOffsetX,labelOffsetY:e.labelOffsetY??t.labelOffsetY};this.nodes.set(e.id,n)}addLink(e){this.links.push(e)}addTrend(e){this.trends.set(e.nodeId,e)}startPipeline(e){this.pipelines.set(e,{nodeId:e,componentIds:[]});let t=this.nodes.get(e);t&&(t.isPipelineParent=!0)}addPipelineComponent(e,t){let n=this.pipelines.get(e);n&&n.componentIds.push(t);let r=this.nodes.get(t);r&&(r.inPipeline=!0)}addAnnotation(e){this.annotations.push(e)}addNote(e){this.notes.push(e)}addAccelerator(e){this.accelerators.push(e)}addDeaccelerator(e){this.deaccelerators.push(e)}setAnnotationsBox(e,t){this.annotationsBox={x:e,y:t}}setAxes(e){this.axes={...this.axes,...e}}setSize(e,t){this.size={width:e,height:t}}getNode(e){return this.nodes.get(e)}resolveNodeId(e){if(this.nodes.has(e))return e;for(let[t,n]of this.nodes)if(n.label===e)return t;return e}build(){let e=[];for(let t of this.nodes.values()){if(typeof t.x!=`number`||typeof t.y!=`number`)throw Error(`Node "${t.label}" is missing coordinates`);e.push(t)}return{nodes:e,links:[...this.links],trends:[...this.trends.values()],pipelines:[...this.pipelines.values()],annotations:[...this.annotations],notes:[...this.notes],accelerators:[...this.accelerators],deaccelerators:[...this.deaccelerators],annotationsBox:this.annotationsBox,axes:{...this.axes},size:this.size}}clear(){this.nodes.clear(),this.links=[],this.trends.clear(),this.pipelines.clear(),this.annotations=[],this.notes=[],this.accelerators=[],this.deaccelerators=[],this.annotationsBox=void 0,this.axes={},this.size=void 0}};function w(){return h()[`wardley-beta`]}u(w,`getConfig`);function T(e,t,n,r,i,a,o,s,c){C.addNode({id:e,label:t,x:n,y:r,className:i,labelOffsetX:a,labelOffsetY:o,inertia:s,sourceStrategy:c})}u(T,`addNode`);function E(e,t,n=!1,r,i){C.addLink({source:e,target:t,dashed:n,label:r,flow:i})}u(E,`addLink`);function D(e,t,n){C.addTrend({nodeId:e,targetX:t,targetY:n})}u(D,`addTrend`);function O(e,t,n){C.addAnnotation({number:e,coordinates:t,text:n})}u(O,`addAnnotation`);function k(e,t,n){C.addNote({text:e,x:t,y:n})}u(k,`addNote`);function A(e,t,n){C.addAccelerator({name:e,x:t,y:n})}u(A,`addAccelerator`);function j(e,t,n){C.addDeaccelerator({name:e,x:t,y:n})}u(j,`addDeaccelerator`);function M(e,t){C.setAnnotationsBox(e,t)}u(M,`setAnnotationsBox`);function N(e,t){C.setSize(e,t)}u(N,`setSize`);function P(e){C.startPipeline(e)}u(P,`startPipeline`);function F(e,t){C.addPipelineComponent(e,t)}u(F,`addPipelineComponent`);function I(e){C.setAxes(e)}u(I,`updateAxes`);function L(e){return C.getNode(e)}u(L,`getNode`);function R(e){return C.resolveNodeId(e)}u(R,`resolveNodeId`);function z(){return C.build()}u(z,`getWardleyData`);function B(){C.clear(),r()}u(B,`clear`);var V={getConfig:w,addNode:T,addLink:E,addTrend:D,addAnnotation:O,addNote:k,addAccelerator:A,addDeaccelerator:j,setAnnotationsBox:M,setSize:N,startPipeline:P,addPipelineComponent:F,updateAxes:I,getNode:L,resolveNodeId:R,getWardleyData:z,clear:B,setAccTitle:c,getAccTitle:g,setDiagramTitle:o,getDiagramTitle:l,getAccDescription:s,setAccDescription:d},H=[`Genesis`,`Custom Built`,`Product`,`Commodity`],U=u(()=>{let{themeVariables:e}=h();return{backgroundColor:e.wardley?.backgroundColor??e.background??`#fff`,axisColor:e.wardley?.axisColor??`#000`,axisTextColor:e.wardley?.axisTextColor??e.primaryTextColor??`#222`,gridColor:e.wardley?.gridColor??`rgba(100, 100, 100, 0.2)`,componentFill:e.wardley?.componentFill??`#fff`,componentStroke:e.wardley?.componentStroke??`#000`,componentLabelColor:e.wardley?.componentLabelColor??e.primaryTextColor??`#222`,linkStroke:e.wardley?.linkStroke??`#000`,evolutionStroke:e.wardley?.evolutionStroke??`#dc3545`,annotationStroke:e.wardley?.annotationStroke??`#000`,annotationTextColor:e.wardley?.annotationTextColor??e.primaryTextColor??`#222`,annotationFill:e.wardley?.annotationFill??e.background??`#fff`}},`getTheme`),W=u(()=>{let e=h()[`wardley-beta`];return{width:e?.width??900,height:e?.height??600,padding:e?.padding??48,nodeRadius:e?.nodeRadius??6,nodeLabelOffset:e?.nodeLabelOffset??8,axisFontSize:e?.axisFontSize??12,labelFontSize:e?.labelFontSize??10,showGrid:e?.showGrid??!1,useMaxWidth:e?.useMaxWidth??!0}},`getConfigValues`),G={parser:S,db:V,renderer:{draw:u((e,t,r,i)=>{n.debug(`Rendering Wardley map
2
2
  `+e);let o=W(),s=U(),c=o.nodeRadius*1.6,l=i.db,d=l.getWardleyData(),p=l.getDiagramTitle(),m=d.size?.width??o.width,h=d.size?.height??o.height,g=f(t);g.selectAll(`*`).remove(),a(g,h,m,o.useMaxWidth),g.attr(`viewBox`,`0 0 ${m} ${h}`);let _=g.append(`g`).attr(`class`,`wardley-map`),v=g.append(`defs`);v.append(`marker`).attr(`id`,`arrow-${t}`).attr(`viewBox`,`0 0 10 10`).attr(`refX`,9).attr(`refY`,5).attr(`markerWidth`,6).attr(`markerHeight`,6).attr(`orient`,`auto-start-reverse`).append(`path`).attr(`d`,`M 0 0 L 10 5 L 0 10 z`).attr(`fill`,s.evolutionStroke).attr(`stroke`,`none`),v.append(`marker`).attr(`id`,`link-arrow-end-${t}`).attr(`viewBox`,`0 0 10 10`).attr(`refX`,9).attr(`refY`,5).attr(`markerWidth`,5).attr(`markerHeight`,5).attr(`orient`,`auto`).append(`path`).attr(`d`,`M 0 0 L 10 5 L 0 10 z`).attr(`fill`,s.linkStroke).attr(`stroke`,`none`),v.append(`marker`).attr(`id`,`link-arrow-start-${t}`).attr(`viewBox`,`0 0 10 10`).attr(`refX`,1).attr(`refY`,5).attr(`markerWidth`,5).attr(`markerHeight`,5).attr(`orient`,`auto`).append(`path`).attr(`d`,`M 10 0 L 0 5 L 10 10 z`).attr(`fill`,s.linkStroke).attr(`stroke`,`none`),_.append(`rect`).attr(`class`,`wardley-background`).attr(`width`,m).attr(`height`,h).attr(`fill`,s.backgroundColor);let y=m-o.padding*2,b=h-o.padding*2;p&&_.append(`text`).attr(`class`,`wardley-title`).attr(`x`,m/2).attr(`y`,o.padding/2).attr(`fill`,s.axisTextColor).attr(`font-size`,o.axisFontSize*1.05).attr(`font-weight`,`bold`).attr(`text-anchor`,`middle`).attr(`dominant-baseline`,`middle`).text(p);let x=u(e=>o.padding+e/100*y,`projectX`),S=u(e=>h-o.padding-e/100*b,`projectY`),C=_.append(`g`).attr(`class`,`wardley-axes`);C.append(`line`).attr(`x1`,o.padding).attr(`x2`,m-o.padding).attr(`y1`,h-o.padding).attr(`y2`,h-o.padding).attr(`stroke`,s.axisColor).attr(`stroke-width`,1),C.append(`line`).attr(`x1`,o.padding).attr(`x2`,o.padding).attr(`y1`,o.padding).attr(`y2`,h-o.padding).attr(`stroke`,s.axisColor).attr(`stroke-width`,1);let w=d.axes.xLabel??`Evolution`,T=d.axes.yLabel??`Visibility`;C.append(`text`).attr(`class`,`wardley-axis-label wardley-axis-label-x`).attr(`x`,o.padding+y/2).attr(`y`,h-o.padding/4).attr(`fill`,s.axisTextColor).attr(`font-size`,o.axisFontSize).attr(`font-weight`,`bold`).attr(`text-anchor`,`middle`).text(w),C.append(`text`).attr(`class`,`wardley-axis-label wardley-axis-label-y`).attr(`x`,o.padding/3).attr(`y`,o.padding+b/2).attr(`fill`,s.axisTextColor).attr(`font-size`,o.axisFontSize).attr(`font-weight`,`bold`).attr(`text-anchor`,`middle`).attr(`transform`,`rotate(-90 ${o.padding/3} ${o.padding+b/2})`).text(T);let E=d.axes.stages&&d.axes.stages.length>0?d.axes.stages:H;if(E.length>0){let e=_.append(`g`).attr(`class`,`wardley-stages`),t=d.axes.stageBoundaries,n=[];if(t&&t.length===E.length){let e=0;t.forEach(t=>{n.push({start:e,end:t}),e=t})}else{let e=1/E.length;E.forEach((t,r)=>{n.push({start:r*e,end:(r+1)*e})})}E.forEach((t,r)=>{let i=n[r],a=o.padding+i.start*y,c=(a+(o.padding+i.end*y))/2;r>0&&e.append(`line`).attr(`x1`,a).attr(`x2`,a).attr(`y1`,o.padding).attr(`y2`,h-o.padding).attr(`stroke`,`#000`).attr(`stroke-width`,1).attr(`stroke-dasharray`,`5 5`).attr(`opacity`,.8),e.append(`text`).attr(`class`,`wardley-stage-label`).attr(`x`,c).attr(`y`,h-o.padding/1.5).attr(`fill`,s.axisTextColor).attr(`font-size`,o.axisFontSize-2).attr(`text-anchor`,`middle`).text(t)})}if(o.showGrid){let e=_.append(`g`).attr(`class`,`wardley-grid`);for(let t=1;t<4;t++){let n=t/4,r=o.padding+y*n;e.append(`line`).attr(`x1`,r).attr(`x2`,r).attr(`y1`,o.padding).attr(`y2`,h-o.padding).attr(`stroke`,s.gridColor).attr(`stroke-dasharray`,`2 6`),e.append(`line`).attr(`x1`,o.padding).attr(`x2`,m-o.padding).attr(`y1`,h-o.padding-b*n).attr(`y2`,h-o.padding-b*n).attr(`stroke`,s.gridColor).attr(`stroke-dasharray`,`2 6`)}}let D=new Map;if(d.nodes.forEach(e=>{D.set(e.id,{x:x(e.x),y:S(e.y),node:e})}),d.pipelines.length>0){let e=_.append(`g`).attr(`class`,`wardley-pipelines`),t=_.append(`g`).attr(`class`,`wardley-pipeline-links`);d.pipelines.forEach(n=>{if(n.componentIds.length===0)return;let r=n.componentIds.map(e=>({id:e,pos:D.get(e),node:d.nodes.find(t=>t.id===e)})).filter(e=>e.pos&&e.node).sort((e,t)=>e.node.x-t.node.x);for(let e=0;e<r.length-1;e++){let n=r[e],i=r[e+1];t.append(`line`).attr(`class`,`wardley-pipeline-evolution-link`).attr(`x1`,n.pos.x).attr(`y1`,n.pos.y).attr(`x2`,i.pos.x).attr(`y2`,i.pos.y).attr(`stroke`,s.linkStroke).attr(`stroke-width`,1).attr(`stroke-dasharray`,`4 4`)}let i=1/0,a=-1/0,l=0;if(n.componentIds.forEach(e=>{let t=D.get(e);t&&(i=Math.min(i,t.x),a=Math.max(a,t.x),l=t.y)}),i!==1/0&&a!==-1/0){let t=o.nodeRadius*4,r=l-t/2,u=D.get(n.nodeId);u&&(u.x=(i+a)/2,u.y=r-c/6),e.append(`rect`).attr(`class`,`wardley-pipeline-box`).attr(`x`,i-15).attr(`y`,r).attr(`width`,a-i+30).attr(`height`,t).attr(`fill`,`none`).attr(`stroke`,s.axisColor).attr(`stroke-width`,1.5).attr(`rx`,4).attr(`ry`,4)}})}let O=_.append(`g`).attr(`class`,`wardley-links`),k=new Map;d.pipelines.forEach(e=>{k.set(e.nodeId,new Set(e.componentIds))});let A=d.links.filter(e=>!(!D.has(e.source)||!D.has(e.target)||k.get(e.target)?.has(e.source)));O.selectAll(`line`).data(A).enter().append(`line`).attr(`class`,e=>`wardley-link${e.dashed?` wardley-link--dashed`:``}`).attr(`x1`,e=>{let t=D.get(e.source),n=D.get(e.target),r=d.nodes.find(t=>t.id===e.source).isPipelineParent?c/Math.sqrt(2):o.nodeRadius,i=n.x-t.x,a=n.y-t.y,s=Math.sqrt(i*i+a*a);return t.x+i/s*r}).attr(`y1`,e=>{let t=D.get(e.source),n=D.get(e.target),r=d.nodes.find(t=>t.id===e.source).isPipelineParent?c/Math.sqrt(2):o.nodeRadius,i=n.x-t.x,a=n.y-t.y,s=Math.sqrt(i*i+a*a);return t.y+a/s*r}).attr(`x2`,e=>{let t=D.get(e.source),n=D.get(e.target),r=d.nodes.find(t=>t.id===e.target).isPipelineParent?c/Math.sqrt(2):o.nodeRadius,i=t.x-n.x,a=t.y-n.y,s=Math.sqrt(i*i+a*a);return n.x+i/s*r}).attr(`y2`,e=>{let t=D.get(e.source),n=D.get(e.target),r=d.nodes.find(t=>t.id===e.target).isPipelineParent?c/Math.sqrt(2):o.nodeRadius,i=t.x-n.x,a=t.y-n.y,s=Math.sqrt(i*i+a*a);return n.y+a/s*r}).attr(`stroke`,s.linkStroke).attr(`stroke-width`,1).attr(`stroke-dasharray`,e=>e.dashed?`6 6`:null).attr(`marker-end`,e=>e.flow===`forward`||e.flow===`bidirectional`?`url(#link-arrow-end-${t})`:null).attr(`marker-start`,e=>e.flow===`backward`||e.flow===`bidirectional`?`url(#link-arrow-start-${t})`:null),O.selectAll(`text`).data(A.filter(e=>e.label)).enter().append(`text`).attr(`class`,`wardley-link-label`).attr(`x`,e=>{let t=D.get(e.source),n=D.get(e.target),r=(t.x+n.x)/2,i=n.y-t.y,a=n.x-t.x;return r+i/Math.sqrt(a*a+i*i)*8}).attr(`y`,e=>{let t=D.get(e.source),n=D.get(e.target),r=(t.y+n.y)/2,i=n.x-t.x,a=n.y-t.y,o=Math.sqrt(i*i+a*a);return r+-i/o*8}).attr(`fill`,s.axisTextColor).attr(`font-size`,o.labelFontSize).attr(`text-anchor`,`middle`).attr(`dominant-baseline`,`middle`).attr(`transform`,e=>{let t=D.get(e.source),n=D.get(e.target),r=(t.x+n.x)/2,i=(t.y+n.y)/2,a=n.x-t.x,o=n.y-t.y,s=Math.sqrt(a*a+o*o),c=o/s,l=-a/s,u=r+c*8,d=i+l*8,f=Math.atan2(o,a)*180/Math.PI;return(f>90||f<-90)&&(f+=180),`rotate(${f} ${u} ${d})`}).text(e=>e.label);let j=_.append(`g`).attr(`class`,`wardley-trends`),M=d.trends.map(e=>{let t=D.get(e.nodeId);if(!t)return null;let n=x(e.targetX),r=S(e.targetY),i=n-t.x,a=r-t.y,s=Math.sqrt(i*i+a*a),c=o.nodeRadius+2;return{origin:t,targetX:n,targetY:r,adjustedX2:s>c?n-i/s*c:n,adjustedY2:s>c?r-a/s*c:r}}).filter(e=>e!==null);j.selectAll(`line`).data(M).enter().append(`line`).attr(`class`,`wardley-trend`).attr(`x1`,e=>e.origin.x).attr(`y1`,e=>e.origin.y).attr(`x2`,e=>e.adjustedX2).attr(`y2`,e=>e.adjustedY2).attr(`stroke`,s.evolutionStroke).attr(`stroke-width`,1).attr(`stroke-dasharray`,`4 4`).attr(`marker-end`,`url(#arrow-${t})`);let N=_.append(`g`).attr(`class`,`wardley-nodes`).selectAll(`g`).data(d.nodes).enter().append(`g`).attr(`class`,e=>[`wardley-node`,e.className?`wardley-node--${e.className}`:``].filter(Boolean).join(` `));N.filter(e=>e.sourceStrategy===`outsource`).append(`circle`).attr(`class`,`wardley-outsource-overlay`).attr(`cx`,e=>D.get(e.id).x).attr(`cy`,e=>D.get(e.id).y).attr(`r`,o.nodeRadius*2).attr(`fill`,`#666`).attr(`stroke`,s.componentStroke).attr(`stroke-width`,1),N.filter(e=>e.sourceStrategy===`buy`).append(`circle`).attr(`class`,`wardley-buy-overlay`).attr(`cx`,e=>D.get(e.id).x).attr(`cy`,e=>D.get(e.id).y).attr(`r`,o.nodeRadius*2).attr(`fill`,`#ccc`).attr(`stroke`,s.componentStroke).attr(`stroke-width`,1),N.filter(e=>e.sourceStrategy===`build`).append(`circle`).attr(`class`,`wardley-build-overlay`).attr(`cx`,e=>D.get(e.id).x).attr(`cy`,e=>D.get(e.id).y).attr(`r`,o.nodeRadius*2).attr(`fill`,`#eee`).attr(`stroke`,`#000`).attr(`stroke-width`,1);let P=N.filter(e=>e.sourceStrategy===`market`);P.append(`circle`).attr(`class`,`wardley-market-overlay`).attr(`cx`,e=>D.get(e.id).x).attr(`cy`,e=>D.get(e.id).y).attr(`r`,o.nodeRadius*2).attr(`fill`,`white`).attr(`stroke`,s.componentStroke).attr(`stroke-width`,1),N.filter(e=>!e.isPipelineParent&&e.sourceStrategy!==`market`&&e.className!==`anchor`).append(`circle`).attr(`cx`,e=>D.get(e.id).x).attr(`cy`,e=>D.get(e.id).y).attr(`r`,o.nodeRadius).attr(`fill`,s.componentFill).attr(`stroke`,s.componentStroke).attr(`stroke-width`,1);let F=o.nodeRadius*.7,I=o.nodeRadius*1.2;if(P.append(`line`).attr(`class`,`wardley-market-line`).attr(`x1`,e=>D.get(e.id).x).attr(`y1`,e=>D.get(e.id).y-I).attr(`x2`,e=>D.get(e.id).x-I*Math.cos(Math.PI/6)).attr(`y2`,e=>D.get(e.id).y+I*Math.sin(Math.PI/6)).attr(`stroke`,s.componentStroke).attr(`stroke-width`,1),P.append(`line`).attr(`class`,`wardley-market-line`).attr(`x1`,e=>D.get(e.id).x-I*Math.cos(Math.PI/6)).attr(`y1`,e=>D.get(e.id).y+I*Math.sin(Math.PI/6)).attr(`x2`,e=>D.get(e.id).x+I*Math.cos(Math.PI/6)).attr(`y2`,e=>D.get(e.id).y+I*Math.sin(Math.PI/6)).attr(`stroke`,s.componentStroke).attr(`stroke-width`,1),P.append(`line`).attr(`class`,`wardley-market-line`).attr(`x1`,e=>D.get(e.id).x+I*Math.cos(Math.PI/6)).attr(`y1`,e=>D.get(e.id).y+I*Math.sin(Math.PI/6)).attr(`x2`,e=>D.get(e.id).x).attr(`y2`,e=>D.get(e.id).y-I).attr(`stroke`,s.componentStroke).attr(`stroke-width`,1),P.append(`circle`).attr(`class`,`wardley-market-dot`).attr(`cx`,e=>D.get(e.id).x).attr(`cy`,e=>D.get(e.id).y-I).attr(`r`,F).attr(`fill`,`white`).attr(`stroke`,s.componentStroke).attr(`stroke-width`,2),P.append(`circle`).attr(`class`,`wardley-market-dot`).attr(`cx`,e=>D.get(e.id).x-I*Math.cos(Math.PI/6)).attr(`cy`,e=>D.get(e.id).y+I*Math.sin(Math.PI/6)).attr(`r`,F).attr(`fill`,`white`).attr(`stroke`,s.componentStroke).attr(`stroke-width`,2),P.append(`circle`).attr(`class`,`wardley-market-dot`).attr(`cx`,e=>D.get(e.id).x+I*Math.cos(Math.PI/6)).attr(`cy`,e=>D.get(e.id).y+I*Math.sin(Math.PI/6)).attr(`r`,F).attr(`fill`,`white`).attr(`stroke`,s.componentStroke).attr(`stroke-width`,2),N.filter(e=>e.isPipelineParent===!0).append(`rect`).attr(`x`,e=>D.get(e.id).x-c/2).attr(`y`,e=>D.get(e.id).y-c/2).attr(`width`,c).attr(`height`,c).attr(`fill`,s.componentFill).attr(`stroke`,s.componentStroke).attr(`stroke-width`,1),N.filter(e=>e.inertia===!0).append(`line`).attr(`class`,`wardley-inertia`).attr(`x1`,e=>{let t=D.get(e.id),n=e.isPipelineParent?c/2+15:o.nodeRadius+15;return e.sourceStrategy&&(n+=o.nodeRadius+10),t.x+n}).attr(`y1`,e=>{let t=D.get(e.id),n=e.isPipelineParent?c:o.nodeRadius*2;return t.y-n/2}).attr(`x2`,e=>{let t=D.get(e.id),n=e.isPipelineParent?c/2+15:o.nodeRadius+15;return e.sourceStrategy&&(n+=o.nodeRadius+10),t.x+n}).attr(`y2`,e=>{let t=D.get(e.id),n=e.isPipelineParent?c:o.nodeRadius*2;return t.y+n/2}).attr(`stroke`,s.componentStroke).attr(`stroke-width`,6),N.append(`text`).attr(`x`,e=>{let t=D.get(e.id);if(e.className===`anchor`)return e.labelOffsetX===void 0?t.x:t.x+e.labelOffsetX;let n=o.nodeLabelOffset;e.sourceStrategy&&e.labelOffsetX===void 0&&(n+=10);let r=e.labelOffsetX??n;return t.x+r}).attr(`y`,e=>{let t=D.get(e.id);if(e.className===`anchor`)return e.labelOffsetY===void 0?t.y-3:t.y+e.labelOffsetY;let n=-o.nodeLabelOffset;e.sourceStrategy&&e.labelOffsetY===void 0&&(n-=10);let r=e.labelOffsetY??n;return t.y+r}).attr(`class`,`wardley-node-label`).attr(`fill`,e=>e.className===`evolved`?s.evolutionStroke:e.className===`anchor`?`#000`:s.componentLabelColor).attr(`font-size`,o.labelFontSize).attr(`font-weight`,e=>e.className===`anchor`?`bold`:`normal`).attr(`text-anchor`,e=>e.className===`anchor`?`middle`:`start`).attr(`dominant-baseline`,e=>e.className===`anchor`?`middle`:`auto`).text(e=>e.label),d.annotations.length>0){let e=_.append(`g`).attr(`class`,`wardley-annotations`);if(d.annotations.forEach(t=>{let n=t.coordinates.map(e=>({x:x(e.x),y:S(e.y)}));if(n.length>1)for(let t=0;t<n.length-1;t++)e.append(`line`).attr(`class`,`wardley-annotation-line`).attr(`x1`,n[t].x).attr(`y1`,n[t].y).attr(`x2`,n[t+1].x).attr(`y2`,n[t+1].y).attr(`stroke`,s.axisColor).attr(`stroke-width`,1.5).attr(`stroke-dasharray`,`4 4`);n.forEach(n=>{let r=e.append(`g`).attr(`class`,`wardley-annotation`);r.append(`circle`).attr(`cx`,n.x).attr(`cy`,n.y).attr(`r`,10).attr(`fill`,`white`).attr(`stroke`,s.axisColor).attr(`stroke-width`,1.5),r.append(`text`).attr(`x`,n.x).attr(`y`,n.y).attr(`text-anchor`,`middle`).attr(`dominant-baseline`,`central`).attr(`font-size`,10).attr(`fill`,s.axisTextColor).attr(`font-weight`,`bold`).text(t.number)})}),d.annotationsBox){let t=x(d.annotationsBox.x),n=S(d.annotationsBox.y),r=e.append(`g`).attr(`class`,`wardley-annotations-box`),i=[...d.annotations].filter(e=>e.text).sort((e,t)=>e.number-t.number),a=[];if(i.forEach((e,i)=>{let o=r.append(`text`).attr(`x`,t+10).attr(`y`,n+10+(i+1)*16).attr(`font-size`,11).attr(`fill`,s.axisTextColor).attr(`text-anchor`,`start`).attr(`dominant-baseline`,`middle`).text(`${e.number}. ${e.text}`);a.push(o)}),a.length>0){let e=0,c=0;a.forEach(t=>{let n=t.node(),r=n.getComputedTextLength();e=Math.max(e,r);let i=n.getBBox();c=Math.max(c,i.height)});let l=e+20+105,u=i.length*16+20+c/2,d=o.padding,f=m-o.padding-l,p=o.padding,g=h-o.padding-u;t=Math.max(d,Math.min(t,f)),n=Math.max(p,Math.min(n,g)),a.forEach((e,r)=>{e.attr(`x`,t+10).attr(`y`,n+10+(r+1)*16)}),r.insert(`rect`,`text`).attr(`x`,t).attr(`y`,n).attr(`width`,l).attr(`height`,u).attr(`fill`,`white`).attr(`stroke`,s.axisColor).attr(`stroke-width`,1.5).attr(`rx`,4).attr(`ry`,4)}}}if(d.notes.length>0){let e=_.append(`g`).attr(`class`,`wardley-notes`);d.notes.forEach(t=>{let n=x(t.x),r=S(t.y);e.append(`text`).attr(`x`,n).attr(`y`,r).attr(`text-anchor`,`start`).attr(`font-size`,11).attr(`fill`,s.axisTextColor).attr(`font-weight`,`bold`).text(t.text)})}if(d.accelerators.length>0){let e=_.append(`g`).attr(`class`,`wardley-accelerators`);d.accelerators.forEach(t=>{let n=x(t.x),r=S(t.y),i=`
3
3
  M ${n} ${r-30/2}
4
4
  L ${n+60-20} ${r-30/2}
@@ -1,4 +1,4 @@
1
- import{t as e}from"./linear-TNRQ5Orv.js";import{t}from"./ordinal-hYBb2elL.js";import{t as n}from"./init-D6jRqBbL.js";import{$t as r,An as i,Jt as a,N as o,T as s,Zt as c,_n as l,en as u,gt as d,hn as f,in as p,kn as m,mn as h,mt as g,nn as _,on as v,pn as y,tn as b}from"./MermaidBlock-DCR8WZ17.js";function x(e,t,n){e=+e,t=+t,n=(i=arguments.length)<2?(t=e,e=0,1):i<3?1:+n;for(var r=-1,i=Math.max(0,Math.ceil((t-e)/n))|0,a=Array(i);++r<i;)a[r]=e+r*n;return a}function S(){var e=t().unknown(void 0),r=e.domain,i=e.range,a=0,o=1,s,c,l=!1,u=0,d=0,f=.5;delete e.unknown;function p(){var e=r().length,t=o<a,n=t?o:a,p=t?a:o;s=(p-n)/Math.max(1,e-u+d*2),l&&(s=Math.floor(s)),n+=(p-n-s*(e-u))*f,c=s*(1-u),l&&(n=Math.round(n),c=Math.round(c));var m=x(e).map(function(e){return n+s*e});return i(t?m.reverse():m)}return e.domain=function(e){return arguments.length?(r(e),p()):r()},e.range=function(e){return arguments.length?([a,o]=e,a=+a,o=+o,p()):[a,o]},e.rangeRound=function(e){return[a,o]=e,a=+a,o=+o,l=!0,p()},e.bandwidth=function(){return c},e.step=function(){return s},e.round=function(e){return arguments.length?(l=!!e,p()):l},e.padding=function(e){return arguments.length?(u=Math.min(1,d=+e),p()):u},e.paddingInner=function(e){return arguments.length?(u=Math.min(1,e),p()):u},e.paddingOuter=function(e){return arguments.length?(d=+e,p()):d},e.align=function(e){return arguments.length?(f=Math.max(0,Math.min(1,e)),p()):f},e.copy=function(){return S(r(),[a,o]).round(l).paddingInner(u).paddingOuter(d).align(f)},n.apply(p(),arguments)}var C=(function(){var e=m(function(e,t,n,r){for(n||={},r=e.length;r--;n[e[r]]=t);return n},`o`),t=[1,10,12,14,16,18,19,21,23],n=[2,6],r=[1,3],i=[1,5],a=[1,6],o=[1,7],s=[1,5,10,12,14,16,18,19,21,23,34,35,36],c=[1,25],l=[1,26],u=[1,28],d=[1,29],f=[1,30],p=[1,31],h=[1,32],g=[1,33],_=[1,34],v=[1,35],y=[1,36],b=[1,37],x=[1,43],S=[1,42],C=[1,47],w=[1,50],T=[1,10,12,14,16,18,19,21,23,34,35,36],E=[1,10,12,14,16,18,19,21,23,24,26,27,28,34,35,36],D=[1,10,12,14,16,18,19,21,23,24,26,27,28,34,35,36,41,42,43,44,45,46,47,48,49,50],O=[1,64],k={trace:m(function(){},`trace`),yy:{},symbols_:{error:2,start:3,eol:4,XYCHART:5,chartConfig:6,document:7,CHART_ORIENTATION:8,statement:9,title:10,text:11,X_AXIS:12,parseXAxis:13,Y_AXIS:14,parseYAxis:15,LINE:16,plotData:17,BAR:18,acc_title:19,acc_title_value:20,acc_descr:21,acc_descr_value:22,acc_descr_multiline_value:23,SQUARE_BRACES_START:24,commaSeparatedNumbers:25,SQUARE_BRACES_END:26,NUMBER_WITH_DECIMAL:27,COMMA:28,xAxisData:29,bandData:30,ARROW_DELIMITER:31,commaSeparatedTexts:32,yAxisData:33,NEWLINE:34,SEMI:35,EOF:36,alphaNum:37,STR:38,MD_STR:39,alphaNumToken:40,AMP:41,NUM:42,ALPHA:43,PLUS:44,EQUALS:45,MULT:46,DOT:47,BRKT:48,MINUS:49,UNDERSCORE:50,$accept:0,$end:1},terminals_:{2:`error`,5:`XYCHART`,8:`CHART_ORIENTATION`,10:`title`,12:`X_AXIS`,14:`Y_AXIS`,16:`LINE`,18:`BAR`,19:`acc_title`,20:`acc_title_value`,21:`acc_descr`,22:`acc_descr_value`,23:`acc_descr_multiline_value`,24:`SQUARE_BRACES_START`,26:`SQUARE_BRACES_END`,27:`NUMBER_WITH_DECIMAL`,28:`COMMA`,31:`ARROW_DELIMITER`,34:`NEWLINE`,35:`SEMI`,36:`EOF`,38:`STR`,39:`MD_STR`,41:`AMP`,42:`NUM`,43:`ALPHA`,44:`PLUS`,45:`EQUALS`,46:`MULT`,47:`DOT`,48:`BRKT`,49:`MINUS`,50:`UNDERSCORE`},productions_:[0,[3,2],[3,3],[3,2],[3,1],[6,1],[7,0],[7,2],[9,2],[9,2],[9,2],[9,2],[9,2],[9,3],[9,2],[9,3],[9,2],[9,2],[9,1],[17,3],[25,3],[25,1],[13,1],[13,2],[13,1],[29,1],[29,3],[30,3],[32,3],[32,1],[15,1],[15,2],[15,1],[33,3],[4,1],[4,1],[4,1],[11,1],[11,1],[11,1],[37,1],[37,2],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1]],performAction:m(function(e,t,n,r,i,a,o){var s=a.length-1;switch(i){case 5:r.setOrientation(a[s]);break;case 9:r.setDiagramTitle(a[s].text.trim());break;case 12:r.setLineData({text:``,type:`text`},a[s]);break;case 13:r.setLineData(a[s-1],a[s]);break;case 14:r.setBarData({text:``,type:`text`},a[s]);break;case 15:r.setBarData(a[s-1],a[s]);break;case 16:this.$=a[s].trim(),r.setAccTitle(this.$);break;case 17:case 18:this.$=a[s].trim(),r.setAccDescription(this.$);break;case 19:this.$=a[s-1];break;case 20:this.$=[Number(a[s-2]),...a[s]];break;case 21:this.$=[Number(a[s])];break;case 22:r.setXAxisTitle(a[s]);break;case 23:r.setXAxisTitle(a[s-1]);break;case 24:r.setXAxisTitle({type:`text`,text:``});break;case 25:r.setXAxisBand(a[s]);break;case 26:r.setXAxisRangeData(Number(a[s-2]),Number(a[s]));break;case 27:this.$=a[s-1];break;case 28:this.$=[a[s-2],...a[s]];break;case 29:this.$=[a[s]];break;case 30:r.setYAxisTitle(a[s]);break;case 31:r.setYAxisTitle(a[s-1]);break;case 32:r.setYAxisTitle({type:`text`,text:``});break;case 33:r.setYAxisRangeData(Number(a[s-2]),Number(a[s]));break;case 37:this.$={text:a[s],type:`text`};break;case 38:this.$={text:a[s],type:`text`};break;case 39:this.$={text:a[s],type:`markdown`};break;case 40:this.$=a[s];break;case 41:this.$=a[s-1]+``+a[s];break}},`anonymous`),table:[e(t,n,{3:1,4:2,7:4,5:r,34:i,35:a,36:o}),{1:[3]},e(t,n,{4:2,7:4,3:8,5:r,34:i,35:a,36:o}),e(t,n,{4:2,7:4,6:9,3:10,5:r,8:[1,11],34:i,35:a,36:o}),{1:[2,4],9:12,10:[1,13],12:[1,14],14:[1,15],16:[1,16],18:[1,17],19:[1,18],21:[1,19],23:[1,20]},e(s,[2,34]),e(s,[2,35]),e(s,[2,36]),{1:[2,1]},e(t,n,{4:2,7:4,3:21,5:r,34:i,35:a,36:o}),{1:[2,3]},e(s,[2,5]),e(t,[2,7],{4:22,34:i,35:a,36:o}),{11:23,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{11:39,13:38,24:x,27:S,29:40,30:41,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{11:45,15:44,27:C,33:46,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{11:49,17:48,24:w,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{11:52,17:51,24:w,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{20:[1,53]},{22:[1,54]},e(T,[2,18]),{1:[2,2]},e(T,[2,8]),e(T,[2,9]),e(E,[2,37],{40:55,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b}),e(E,[2,38]),e(E,[2,39]),e(D,[2,40]),e(D,[2,42]),e(D,[2,43]),e(D,[2,44]),e(D,[2,45]),e(D,[2,46]),e(D,[2,47]),e(D,[2,48]),e(D,[2,49]),e(D,[2,50]),e(D,[2,51]),e(T,[2,10]),e(T,[2,22],{30:41,29:56,24:x,27:S}),e(T,[2,24]),e(T,[2,25]),{31:[1,57]},{11:59,32:58,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},e(T,[2,11]),e(T,[2,30],{33:60,27:C}),e(T,[2,32]),{31:[1,61]},e(T,[2,12]),{17:62,24:w},{25:63,27:O},e(T,[2,14]),{17:65,24:w},e(T,[2,16]),e(T,[2,17]),e(D,[2,41]),e(T,[2,23]),{27:[1,66]},{26:[1,67]},{26:[2,29],28:[1,68]},e(T,[2,31]),{27:[1,69]},e(T,[2,13]),{26:[1,70]},{26:[2,21],28:[1,71]},e(T,[2,15]),e(T,[2,26]),e(T,[2,27]),{11:59,32:72,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},e(T,[2,33]),e(T,[2,19]),{25:73,27:O},{26:[2,28]},{26:[2,20]}],defaultActions:{8:[2,1],10:[2,3],21:[2,2],72:[2,28],73:[2,20]},parseError:m(function(e,t){if(t.recoverable)this.trace(e);else{var n=Error(e);throw n.hash=t,n}},`parseError`),parse:m(function(e){var t=this,n=[0],r=[],i=[null],a=[],o=this.table,s=``,c=0,l=0,u=0,d=2,f=1,p=a.slice.call(arguments,1),h=Object.create(this.lexer),g={yy:{}};for(var _ in this.yy)Object.prototype.hasOwnProperty.call(this.yy,_)&&(g.yy[_]=this.yy[_]);h.setInput(e,g.yy),g.yy.lexer=h,g.yy.parser=this,h.yylloc===void 0&&(h.yylloc={});var v=h.yylloc;a.push(v);var y=h.options&&h.options.ranges;typeof g.yy.parseError==`function`?this.parseError=g.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function b(e){n.length-=2*e,i.length-=e,a.length-=e}m(b,`popStack`);function x(){var e=r.pop()||h.lex()||f;return typeof e!=`number`&&(e instanceof Array&&(r=e,e=r.pop()),e=t.symbols_[e]||e),e}m(x,`lex`);for(var S,C,w,T,E,D={},O,k,A,j;;){if(w=n[n.length-1],this.defaultActions[w]?T=this.defaultActions[w]:(S??=x(),T=o[w]&&o[w][S]),T===void 0||!T.length||!T[0]){var M=``;for(O in j=[],o[w])this.terminals_[O]&&O>d&&j.push(`'`+this.terminals_[O]+`'`);M=h.showPosition?`Parse error on line `+(c+1)+`:
1
+ import{t as e}from"./linear-CN9sbKTF.js";import{t}from"./ordinal-hYBb2elL.js";import{t as n}from"./init-D6jRqBbL.js";import{$t as r,An as i,Jt as a,N as o,T as s,Zt as c,_n as l,en as u,gt as d,hn as f,in as p,kn as m,mn as h,mt as g,nn as _,on as v,pn as y,tn as b}from"./MermaidBlock-IOcal8cm.js";function x(e,t,n){e=+e,t=+t,n=(i=arguments.length)<2?(t=e,e=0,1):i<3?1:+n;for(var r=-1,i=Math.max(0,Math.ceil((t-e)/n))|0,a=Array(i);++r<i;)a[r]=e+r*n;return a}function S(){var e=t().unknown(void 0),r=e.domain,i=e.range,a=0,o=1,s,c,l=!1,u=0,d=0,f=.5;delete e.unknown;function p(){var e=r().length,t=o<a,n=t?o:a,p=t?a:o;s=(p-n)/Math.max(1,e-u+d*2),l&&(s=Math.floor(s)),n+=(p-n-s*(e-u))*f,c=s*(1-u),l&&(n=Math.round(n),c=Math.round(c));var m=x(e).map(function(e){return n+s*e});return i(t?m.reverse():m)}return e.domain=function(e){return arguments.length?(r(e),p()):r()},e.range=function(e){return arguments.length?([a,o]=e,a=+a,o=+o,p()):[a,o]},e.rangeRound=function(e){return[a,o]=e,a=+a,o=+o,l=!0,p()},e.bandwidth=function(){return c},e.step=function(){return s},e.round=function(e){return arguments.length?(l=!!e,p()):l},e.padding=function(e){return arguments.length?(u=Math.min(1,d=+e),p()):u},e.paddingInner=function(e){return arguments.length?(u=Math.min(1,e),p()):u},e.paddingOuter=function(e){return arguments.length?(d=+e,p()):d},e.align=function(e){return arguments.length?(f=Math.max(0,Math.min(1,e)),p()):f},e.copy=function(){return S(r(),[a,o]).round(l).paddingInner(u).paddingOuter(d).align(f)},n.apply(p(),arguments)}var C=(function(){var e=m(function(e,t,n,r){for(n||={},r=e.length;r--;n[e[r]]=t);return n},`o`),t=[1,10,12,14,16,18,19,21,23],n=[2,6],r=[1,3],i=[1,5],a=[1,6],o=[1,7],s=[1,5,10,12,14,16,18,19,21,23,34,35,36],c=[1,25],l=[1,26],u=[1,28],d=[1,29],f=[1,30],p=[1,31],h=[1,32],g=[1,33],_=[1,34],v=[1,35],y=[1,36],b=[1,37],x=[1,43],S=[1,42],C=[1,47],w=[1,50],T=[1,10,12,14,16,18,19,21,23,34,35,36],E=[1,10,12,14,16,18,19,21,23,24,26,27,28,34,35,36],D=[1,10,12,14,16,18,19,21,23,24,26,27,28,34,35,36,41,42,43,44,45,46,47,48,49,50],O=[1,64],k={trace:m(function(){},`trace`),yy:{},symbols_:{error:2,start:3,eol:4,XYCHART:5,chartConfig:6,document:7,CHART_ORIENTATION:8,statement:9,title:10,text:11,X_AXIS:12,parseXAxis:13,Y_AXIS:14,parseYAxis:15,LINE:16,plotData:17,BAR:18,acc_title:19,acc_title_value:20,acc_descr:21,acc_descr_value:22,acc_descr_multiline_value:23,SQUARE_BRACES_START:24,commaSeparatedNumbers:25,SQUARE_BRACES_END:26,NUMBER_WITH_DECIMAL:27,COMMA:28,xAxisData:29,bandData:30,ARROW_DELIMITER:31,commaSeparatedTexts:32,yAxisData:33,NEWLINE:34,SEMI:35,EOF:36,alphaNum:37,STR:38,MD_STR:39,alphaNumToken:40,AMP:41,NUM:42,ALPHA:43,PLUS:44,EQUALS:45,MULT:46,DOT:47,BRKT:48,MINUS:49,UNDERSCORE:50,$accept:0,$end:1},terminals_:{2:`error`,5:`XYCHART`,8:`CHART_ORIENTATION`,10:`title`,12:`X_AXIS`,14:`Y_AXIS`,16:`LINE`,18:`BAR`,19:`acc_title`,20:`acc_title_value`,21:`acc_descr`,22:`acc_descr_value`,23:`acc_descr_multiline_value`,24:`SQUARE_BRACES_START`,26:`SQUARE_BRACES_END`,27:`NUMBER_WITH_DECIMAL`,28:`COMMA`,31:`ARROW_DELIMITER`,34:`NEWLINE`,35:`SEMI`,36:`EOF`,38:`STR`,39:`MD_STR`,41:`AMP`,42:`NUM`,43:`ALPHA`,44:`PLUS`,45:`EQUALS`,46:`MULT`,47:`DOT`,48:`BRKT`,49:`MINUS`,50:`UNDERSCORE`},productions_:[0,[3,2],[3,3],[3,2],[3,1],[6,1],[7,0],[7,2],[9,2],[9,2],[9,2],[9,2],[9,2],[9,3],[9,2],[9,3],[9,2],[9,2],[9,1],[17,3],[25,3],[25,1],[13,1],[13,2],[13,1],[29,1],[29,3],[30,3],[32,3],[32,1],[15,1],[15,2],[15,1],[33,3],[4,1],[4,1],[4,1],[11,1],[11,1],[11,1],[37,1],[37,2],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1],[40,1]],performAction:m(function(e,t,n,r,i,a,o){var s=a.length-1;switch(i){case 5:r.setOrientation(a[s]);break;case 9:r.setDiagramTitle(a[s].text.trim());break;case 12:r.setLineData({text:``,type:`text`},a[s]);break;case 13:r.setLineData(a[s-1],a[s]);break;case 14:r.setBarData({text:``,type:`text`},a[s]);break;case 15:r.setBarData(a[s-1],a[s]);break;case 16:this.$=a[s].trim(),r.setAccTitle(this.$);break;case 17:case 18:this.$=a[s].trim(),r.setAccDescription(this.$);break;case 19:this.$=a[s-1];break;case 20:this.$=[Number(a[s-2]),...a[s]];break;case 21:this.$=[Number(a[s])];break;case 22:r.setXAxisTitle(a[s]);break;case 23:r.setXAxisTitle(a[s-1]);break;case 24:r.setXAxisTitle({type:`text`,text:``});break;case 25:r.setXAxisBand(a[s]);break;case 26:r.setXAxisRangeData(Number(a[s-2]),Number(a[s]));break;case 27:this.$=a[s-1];break;case 28:this.$=[a[s-2],...a[s]];break;case 29:this.$=[a[s]];break;case 30:r.setYAxisTitle(a[s]);break;case 31:r.setYAxisTitle(a[s-1]);break;case 32:r.setYAxisTitle({type:`text`,text:``});break;case 33:r.setYAxisRangeData(Number(a[s-2]),Number(a[s]));break;case 37:this.$={text:a[s],type:`text`};break;case 38:this.$={text:a[s],type:`text`};break;case 39:this.$={text:a[s],type:`markdown`};break;case 40:this.$=a[s];break;case 41:this.$=a[s-1]+``+a[s];break}},`anonymous`),table:[e(t,n,{3:1,4:2,7:4,5:r,34:i,35:a,36:o}),{1:[3]},e(t,n,{4:2,7:4,3:8,5:r,34:i,35:a,36:o}),e(t,n,{4:2,7:4,6:9,3:10,5:r,8:[1,11],34:i,35:a,36:o}),{1:[2,4],9:12,10:[1,13],12:[1,14],14:[1,15],16:[1,16],18:[1,17],19:[1,18],21:[1,19],23:[1,20]},e(s,[2,34]),e(s,[2,35]),e(s,[2,36]),{1:[2,1]},e(t,n,{4:2,7:4,3:21,5:r,34:i,35:a,36:o}),{1:[2,3]},e(s,[2,5]),e(t,[2,7],{4:22,34:i,35:a,36:o}),{11:23,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{11:39,13:38,24:x,27:S,29:40,30:41,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{11:45,15:44,27:C,33:46,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{11:49,17:48,24:w,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{11:52,17:51,24:w,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},{20:[1,53]},{22:[1,54]},e(T,[2,18]),{1:[2,2]},e(T,[2,8]),e(T,[2,9]),e(E,[2,37],{40:55,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b}),e(E,[2,38]),e(E,[2,39]),e(D,[2,40]),e(D,[2,42]),e(D,[2,43]),e(D,[2,44]),e(D,[2,45]),e(D,[2,46]),e(D,[2,47]),e(D,[2,48]),e(D,[2,49]),e(D,[2,50]),e(D,[2,51]),e(T,[2,10]),e(T,[2,22],{30:41,29:56,24:x,27:S}),e(T,[2,24]),e(T,[2,25]),{31:[1,57]},{11:59,32:58,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},e(T,[2,11]),e(T,[2,30],{33:60,27:C}),e(T,[2,32]),{31:[1,61]},e(T,[2,12]),{17:62,24:w},{25:63,27:O},e(T,[2,14]),{17:65,24:w},e(T,[2,16]),e(T,[2,17]),e(D,[2,41]),e(T,[2,23]),{27:[1,66]},{26:[1,67]},{26:[2,29],28:[1,68]},e(T,[2,31]),{27:[1,69]},e(T,[2,13]),{26:[1,70]},{26:[2,21],28:[1,71]},e(T,[2,15]),e(T,[2,26]),e(T,[2,27]),{11:59,32:72,37:24,38:c,39:l,40:27,41:u,42:d,43:f,44:p,45:h,46:g,47:_,48:v,49:y,50:b},e(T,[2,33]),e(T,[2,19]),{25:73,27:O},{26:[2,28]},{26:[2,20]}],defaultActions:{8:[2,1],10:[2,3],21:[2,2],72:[2,28],73:[2,20]},parseError:m(function(e,t){if(t.recoverable)this.trace(e);else{var n=Error(e);throw n.hash=t,n}},`parseError`),parse:m(function(e){var t=this,n=[0],r=[],i=[null],a=[],o=this.table,s=``,c=0,l=0,u=0,d=2,f=1,p=a.slice.call(arguments,1),h=Object.create(this.lexer),g={yy:{}};for(var _ in this.yy)Object.prototype.hasOwnProperty.call(this.yy,_)&&(g.yy[_]=this.yy[_]);h.setInput(e,g.yy),g.yy.lexer=h,g.yy.parser=this,h.yylloc===void 0&&(h.yylloc={});var v=h.yylloc;a.push(v);var y=h.options&&h.options.ranges;typeof g.yy.parseError==`function`?this.parseError=g.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function b(e){n.length-=2*e,i.length-=e,a.length-=e}m(b,`popStack`);function x(){var e=r.pop()||h.lex()||f;return typeof e!=`number`&&(e instanceof Array&&(r=e,e=r.pop()),e=t.symbols_[e]||e),e}m(x,`lex`);for(var S,C,w,T,E,D={},O,k,A,j;;){if(w=n[n.length-1],this.defaultActions[w]?T=this.defaultActions[w]:(S??=x(),T=o[w]&&o[w][S]),T===void 0||!T.length||!T[0]){var M=``;for(O in j=[],o[w])this.terminals_[O]&&O>d&&j.push(`'`+this.terminals_[O]+`'`);M=h.showPosition?`Parse error on line `+(c+1)+`:
2
2
  `+h.showPosition()+`
3
3
  Expecting `+j.join(`, `)+`, got '`+(this.terminals_[S]||S)+`'`:`Parse error on line `+(c+1)+`: Unexpected `+(S==f?`end of input`:`'`+(this.terminals_[S]||S)+`'`),this.parseError(M,{text:h.match,token:this.terminals_[S]||S,line:h.yylineno,loc:v,expected:j})}if(T[0]instanceof Array&&T.length>1)throw Error(`Parse Error: multiple actions possible at state: `+w+`, token: `+S);switch(T[0]){case 1:n.push(S),i.push(h.yytext),a.push(h.yylloc),n.push(T[1]),S=null,C?(S=C,C=null):(l=h.yyleng,s=h.yytext,c=h.yylineno,v=h.yylloc,u>0&&u--);break;case 2:if(k=this.productions_[T[1]][1],D.$=i[i.length-k],D._$={first_line:a[a.length-(k||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(k||1)].first_column,last_column:a[a.length-1].last_column},y&&(D._$.range=[a[a.length-(k||1)].range[0],a[a.length-1].range[1]]),E=this.performAction.apply(D,[s,l,c,g.yy,T[1],i,a].concat(p)),E!==void 0)return E;k&&(n=n.slice(0,-1*k*2),i=i.slice(0,-1*k),a=a.slice(0,-1*k)),n.push(this.productions_[T[1]][0]),i.push(D.$),a.push(D._$),A=o[n[n.length-2]][n[n.length-1]],n.push(A);break;case 3:return!0}}return!0},`parse`)};k.lexer=(function(){return{EOF:1,parseError:m(function(e,t){if(this.yy.parser)this.yy.parser.parseError(e,t);else throw Error(e)},`parseError`),setInput:m(function(e,t){return this.yy=t||this.yy||{},this._input=e,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match=``,this.conditionStack=[`INITIAL`],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},`setInput`),input:m(function(){var e=this._input[0];return this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e,e.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},`input`),unput:m(function(e){var t=e.length,n=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-t),this.offset-=t;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-t]),this.yyleng=this.yytext.length,this},`unput`),more:m(function(){return this._more=!0,this},`more`),reject:m(function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError(`Lexical error on line `+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
4
4
  `+this.showPosition(),{text:``,token:null,line:this.yylineno});return this},`reject`),less:m(function(e){this.unput(this.match.slice(e))},`less`),pastInput:m(function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(e.length>20?`...`:``)+e.substr(-20).replace(/\n/g,``)},`pastInput`),upcomingInput:m(function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(e.length>20?`...`:``)).replace(/\n/g,``)},`upcomingInput`),showPosition:m(function(){var e=this.pastInput(),t=Array(e.length+1).join(`-`);return e+this.upcomingInput()+`
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" type="image/svg+xml" href="./favicon.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
7
7
  <title>AgentEngine</title>
8
- <script type="module" crossorigin src="./assets/index-BH7-pC0B.js"></script>
8
+ <script type="module" crossorigin src="./assets/index-C00Lwg3L.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="./assets/index-DAURbCsP.css">
10
10
  </head>
11
11
  <body>
@@ -134,30 +134,23 @@ def _create_postgres_backend(
134
134
  if not config.dsn:
135
135
  raise ValueError("KSADK_SESSION_DSN is required when KSADK_SESSION_BACKEND=postgres")
136
136
  from ksadk.sessions.postgres_service import PostgresSessionService
137
-
138
- return PostgresSessionService(
139
- dsn=config.dsn,
140
- namespace=config.namespace,
141
- tenant_id=config.tenant_id,
142
- workspace_id=config.workspace_id,
143
- connect_timeout=_postgres_connect_timeout_seconds(),
137
+ from ksadk.sessions.resilient import ResilientSessionService
138
+
139
+ return ResilientSessionService(
140
+ PostgresSessionService(
141
+ dsn=config.dsn,
142
+ namespace=config.namespace,
143
+ tenant_id=config.tenant_id,
144
+ workspace_id=config.workspace_id,
145
+ connect_timeout=_postgres_connect_timeout_seconds(),
146
+ )
144
147
  )
145
148
 
146
149
 
147
150
  def _postgres_connect_timeout_seconds() -> float:
148
- raw = (
149
- os.getenv("KSADK_SESSION_CONNECT_TIMEOUT")
150
- or os.getenv("KSADK_SESSION_PG_CONNECT_TIMEOUT")
151
- or ""
152
- ).strip()
153
- if not raw:
154
- return 5.0
155
- try:
156
- value = float(raw)
157
- except ValueError:
158
- logger.warning("Invalid KSADK_SESSION_CONNECT_TIMEOUT=%r; using 5 seconds", raw)
159
- return 5.0
160
- return max(0.1, value)
151
+ from ksadk.sessions.resilience import session_backend_timeout_seconds
152
+
153
+ return session_backend_timeout_seconds()
161
154
 
162
155
 
163
156
  def _register_builtin_backends() -> None:
@@ -168,12 +161,15 @@ def _register_builtin_backends() -> None:
168
161
 
169
162
  def describe_session_backend(*, backend: str | None = None) -> dict[str, object]:
170
163
  config = resolve_session_backend_config(backend=backend)
171
- return {
164
+ payload: dict[str, object] = {
172
165
  "Backend": config.backend,
173
166
  "Shared": config.backend == "postgres",
174
167
  "ProductionSafe": config.backend == "postgres",
175
168
  "ContinuityDefault": "semantic/replay" if config.backend == "postgres" else "local_only",
176
169
  }
170
+ if config.backend == "postgres":
171
+ payload.update({"FailureMode": "fail_open", "FallbackBackend": "memory"})
172
+ return payload
177
173
 
178
174
 
179
175
  def log_session_backend_diagnostics(*, backend: str | None = None) -> None:
@@ -79,7 +79,9 @@ class ConversationSessionCore:
79
79
  )
80
80
  return dict(state.state)
81
81
 
82
- async def get_runtime_state_by_session_id(self, session_id: str, runner_key: str) -> dict[str, Any]:
82
+ async def get_runtime_state_by_session_id(
83
+ self, session_id: str, runner_key: str
84
+ ) -> dict[str, Any]:
83
85
  session = await self._load_session(session_id)
84
86
  if session is None:
85
87
  return {}
@@ -271,7 +273,11 @@ class LangGraphSessionAdapter(RunnerSessionAdapter):
271
273
  else:
272
274
  path = "replay"
273
275
  return SessionContinuityStatus(
274
- level=SessionContinuityLevel.RUNTIME if has_checkpointer else SessionContinuityLevel.SEMANTIC,
276
+ level=(
277
+ SessionContinuityLevel.RUNTIME
278
+ if has_checkpointer
279
+ else SessionContinuityLevel.SEMANTIC
280
+ ),
275
281
  path=path,
276
282
  runner=self.runner_key(runner),
277
283
  )
@@ -306,8 +312,26 @@ class ADKSessionAdapter(RunnerSessionAdapter):
306
312
  "KSADK_SESSION_DSN",
307
313
  )
308
314
  )
315
+ is_resumable = bool(getattr(runner, "_resumable", False))
316
+ if is_resumable:
317
+ # P1.3: Level must degrade with backend — in-memory session state
318
+ # cannot survive pod restarts, so RUNTIME is misleading.
319
+ _stm = getattr(runner, "_short_term_memory", None)
320
+ stm_backend = getattr(_stm, "backend", None) if _stm is not None else None
321
+ is_durable = stm_backend is not None and stm_backend != "local"
322
+ level = (
323
+ SessionContinuityLevel.RUNTIME if is_durable
324
+ else SessionContinuityLevel.SEMANTIC
325
+ )
326
+ path = "adk_resume"
327
+ elif has_native_session:
328
+ level = SessionContinuityLevel.SEMANTIC
329
+ path = "native_session"
330
+ else:
331
+ level = SessionContinuityLevel.SEMANTIC
332
+ path = "replay"
309
333
  return SessionContinuityStatus(
310
- level=SessionContinuityLevel.SEMANTIC,
311
- path="native_session" if has_native_session else "replay",
334
+ level=level,
335
+ path=path,
312
336
  runner=self.runner_key(runner),
313
337
  )
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import asyncio
6
6
  import json
7
+ import logging
7
8
  import time
8
9
  from typing import Any, Optional
9
10
  from urllib.parse import urlsplit, urlunsplit
@@ -20,6 +21,9 @@ from ksadk.sessions.errors import SessionBackendUnavailable
20
21
  KSADK_PG_SESSIONS_TABLE = "ksadk_sessions"
21
22
  KSADK_PG_EVENTS_TABLE = "ksadk_events"
22
23
  KSADK_PG_STATES_TABLE = "ksadk_states"
24
+ PG_READABLE_EVENTS_VIEW = "ksadk_session_events_readable"
25
+
26
+ logger = logging.getLogger(__name__)
23
27
 
24
28
 
25
29
  class PostgresSessionService(BaseSessionService):
@@ -70,6 +74,7 @@ class PostgresSessionService(BaseSessionService):
70
74
  first_prompt, last_prompt, state_json, created_at, updated_at, version
71
75
  )
72
76
  VALUES ($1, $2, $3, $4, $5, $6, '', '', '', '', '', $7::jsonb, $8, $9, 0)
77
+ ON CONFLICT (namespace, id) DO NOTHING
73
78
  """,
74
79
  self.namespace,
75
80
  self.tenant_id,
@@ -81,6 +86,13 @@ class PostgresSessionService(BaseSessionService):
81
86
  now,
82
87
  now,
83
88
  )
89
+ persisted = await self._get_session_with_connection(
90
+ connection,
91
+ session_key,
92
+ for_update=True,
93
+ )
94
+ if persisted is None:
95
+ raise RuntimeError(f"Failed to create Postgres session {session_key}")
84
96
  await connection.execute(
85
97
  f"""
86
98
  INSERT INTO {KSADK_PG_STATES_TABLE} (
@@ -93,19 +105,13 @@ class PostgresSessionService(BaseSessionService):
93
105
  self.namespace,
94
106
  self.tenant_id,
95
107
  self.workspace_id,
96
- agent_id,
97
- user_id,
108
+ persisted.agent_id,
109
+ persisted.user_id,
98
110
  session_key,
99
111
  "{}",
100
112
  now,
101
113
  )
102
- return Session(
103
- id=session_key,
104
- agent_id=agent_id,
105
- user_id=user_id,
106
- created_at=now,
107
- updated_at=now,
108
- )
114
+ return persisted
109
115
 
110
116
  async def get_session(self, session_id: str) -> Optional[Session]:
111
117
  await self._ensure_schema()
@@ -545,10 +551,15 @@ class PostgresSessionService(BaseSessionService):
545
551
  )
546
552
 
547
553
  async def aclose(self) -> None:
548
- if self._pool is not None:
549
- await self._pool.close()
550
- self._pool = None
551
- self._schema_ready = False
554
+ pool = self._pool
555
+ self._pool = None
556
+ self._schema_ready = False
557
+ if pool is None:
558
+ return
559
+ try:
560
+ await asyncio.wait_for(pool.close(), timeout=self.connect_timeout)
561
+ except (TimeoutError, OSError, ConnectionError, asyncio.TimeoutError):
562
+ pool.terminate()
552
563
 
553
564
  async def _ensure_pool(self) -> None:
554
565
  if self._pool is not None:
@@ -559,7 +570,7 @@ class PostgresSessionService(BaseSessionService):
559
570
  try:
560
571
  import asyncpg
561
572
  except ImportError as exc:
562
- raise RuntimeError(
573
+ raise SessionBackendUnavailable(
563
574
  "asyncpg is required for KSADK_SESSION_BACKEND=postgres"
564
575
  ) from exc
565
576
  try:
@@ -568,6 +579,7 @@ class PostgresSessionService(BaseSessionService):
568
579
  min_size=self.min_size,
569
580
  max_size=self.max_size,
570
581
  timeout=self.connect_timeout,
582
+ command_timeout=self.connect_timeout,
571
583
  )
572
584
  except (TimeoutError, OSError, ConnectionError, asyncio.TimeoutError) as exc:
573
585
  raise SessionBackendUnavailable(
@@ -656,6 +668,57 @@ class PostgresSessionService(BaseSessionService):
656
668
  ADD COLUMN IF NOT EXISTS workspace_id TEXT NOT NULL DEFAULT 'default';
657
669
  """
658
670
  )
671
+ try:
672
+ await connection.execute(
673
+ f"""
674
+ CREATE OR REPLACE VIEW {PG_READABLE_EVENTS_VIEW} AS
675
+ SELECT
676
+ event_row.namespace,
677
+ event_row.tenant_id,
678
+ event_row.workspace_id,
679
+ session_row.agent_id,
680
+ session_row.user_id,
681
+ session_row.title AS session_title,
682
+ event_row.session_id,
683
+ event_row.seq_id,
684
+ event_row.id AS event_id,
685
+ event_row.invocation_id,
686
+ event_row.author,
687
+ event_row.event_type,
688
+ CASE
689
+ WHEN event_row.event_type = 'user_message' THEN 'user'
690
+ WHEN event_row.event_type IN (
691
+ 'assistant_message', 'reasoning', 'tool_call'
692
+ ) THEN 'assistant'
693
+ WHEN event_row.event_type = 'tool_result' THEN 'tool'
694
+ ELSE NULL
695
+ END AS message_role,
696
+ COALESCE(
697
+ NULLIF(event_row.content_json #>> '{{parts,0,text}}', ''),
698
+ NULLIF(event_row.content_json ->> 'text', ''),
699
+ NULLIF(event_row.metadata_json ->> 'reasoning', ''),
700
+ NULLIF(event_row.metadata_json ->> 'tool_output', '')
701
+ ) AS message_text,
702
+ event_row.metadata_json ->> 'tool_name' AS tool_name,
703
+ CASE
704
+ WHEN event_row.event_type = 'run_status' THEN COALESCE(
705
+ event_row.content_json ->> 'status',
706
+ event_row.metadata_json ->> 'status'
707
+ )
708
+ ELSE NULL
709
+ END AS lifecycle_status,
710
+ to_timestamp(event_row.timestamp) AS created_at,
711
+ event_row.content_json,
712
+ event_row.state_delta_json,
713
+ event_row.metadata_json
714
+ FROM {KSADK_PG_EVENTS_TABLE} AS event_row
715
+ JOIN {KSADK_PG_SESSIONS_TABLE} AS session_row
716
+ ON session_row.namespace = event_row.namespace
717
+ AND session_row.id = event_row.session_id;
718
+ """
719
+ )
720
+ except Exception as exc:
721
+ logger.warning("Postgres readable session view unavailable: %s", exc)
659
722
  self._schema_ready = True
660
723
 
661
724
  async def _get_session_with_connection(
@@ -0,0 +1,52 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ import os
5
+ from collections.abc import Iterator
6
+
7
+ from ksadk.sessions.errors import SessionBackendUnavailable
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ def session_backend_timeout_seconds() -> float:
13
+ raw = (
14
+ os.getenv("KSADK_SESSION_CONNECT_TIMEOUT")
15
+ or os.getenv("KSADK_SESSION_PG_CONNECT_TIMEOUT")
16
+ or ""
17
+ ).strip()
18
+ if not raw:
19
+ return 5.0
20
+ try:
21
+ value = float(raw)
22
+ except ValueError:
23
+ logger.warning("Invalid KSADK_SESSION_CONNECT_TIMEOUT=%r; using 5 seconds", raw)
24
+ return 5.0
25
+ return max(0.1, value)
26
+
27
+
28
+ def _exception_chain(exc: BaseException) -> Iterator[BaseException]:
29
+ seen: set[int] = set()
30
+ current: BaseException | None = exc
31
+ while current is not None and id(current) not in seen:
32
+ seen.add(id(current))
33
+ yield current
34
+ original = getattr(current, "orig", None)
35
+ if isinstance(original, BaseException) and id(original) not in seen:
36
+ current = original
37
+ continue
38
+ current = current.__cause__ or current.__context__
39
+
40
+
41
+ def is_session_backend_failure(exc: BaseException) -> bool:
42
+ """Return whether an exception represents an unavailable database backend."""
43
+ for current in _exception_chain(exc):
44
+ if isinstance(
45
+ current,
46
+ (SessionBackendUnavailable, TimeoutError, OSError, ConnectionError),
47
+ ):
48
+ return True
49
+ module = type(current).__module__
50
+ if module.startswith("asyncpg.") or module.startswith("sqlalchemy."):
51
+ return True
52
+ return False