@qodo/sdk 0.13.4 → 2.0.0-next.1

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 (764) hide show
  1. package/LICENSE +31 -118
  2. package/README.md +133 -121
  3. package/bin/qodo-skills.mjs +13 -0
  4. package/bundled-skills/code-review/SKILL.md +41 -0
  5. package/bundled-skills/pr-summary/SKILL.md +59 -0
  6. package/bundled-skills/test-gen/SKILL.md +47 -0
  7. package/dist/auth/index.browser.d.ts +38 -0
  8. package/dist/auth/index.browser.d.ts.map +1 -0
  9. package/dist/auth/index.browser.js +62 -0
  10. package/dist/auth/index.browser.js.map +1 -0
  11. package/dist/auth/index.d.ts +44 -30
  12. package/dist/auth/index.d.ts.map +1 -1
  13. package/dist/auth/index.js +57 -110
  14. package/dist/auth/index.js.map +1 -1
  15. package/dist/client/AgentsClient.d.ts +33 -0
  16. package/dist/client/AgentsClient.d.ts.map +1 -0
  17. package/dist/client/AgentsClient.js +40 -0
  18. package/dist/client/AgentsClient.js.map +1 -0
  19. package/dist/client/ArtifactsClient.d.ts +43 -0
  20. package/dist/client/ArtifactsClient.d.ts.map +1 -0
  21. package/dist/client/ArtifactsClient.js +54 -0
  22. package/dist/client/ArtifactsClient.js.map +1 -0
  23. package/dist/client/BulletinClient.d.ts +45 -0
  24. package/dist/client/BulletinClient.d.ts.map +1 -0
  25. package/dist/client/BulletinClient.js +51 -0
  26. package/dist/client/BulletinClient.js.map +1 -0
  27. package/dist/client/InfoClient.d.ts +58 -0
  28. package/dist/client/InfoClient.d.ts.map +1 -0
  29. package/dist/client/InfoClient.js +135 -0
  30. package/dist/client/InfoClient.js.map +1 -0
  31. package/dist/client/PipelineClient.d.ts +162 -0
  32. package/dist/client/PipelineClient.d.ts.map +1 -0
  33. package/dist/client/PipelineClient.js +340 -0
  34. package/dist/client/PipelineClient.js.map +1 -0
  35. package/dist/client/QarRegistryClient.d.ts +396 -0
  36. package/dist/client/QarRegistryClient.d.ts.map +1 -0
  37. package/dist/client/QarRegistryClient.js +536 -0
  38. package/dist/client/QarRegistryClient.js.map +1 -0
  39. package/dist/client/QodoClient.d.ts +296 -0
  40. package/dist/client/QodoClient.d.ts.map +1 -0
  41. package/dist/client/QodoClient.js +803 -0
  42. package/dist/client/QodoClient.js.map +1 -0
  43. package/dist/client/SpecsClient.d.ts +121 -0
  44. package/dist/client/SpecsClient.d.ts.map +1 -0
  45. package/dist/client/SpecsClient.js +252 -0
  46. package/dist/client/SpecsClient.js.map +1 -0
  47. package/dist/client/StateClient.d.ts +35 -0
  48. package/dist/client/StateClient.d.ts.map +1 -0
  49. package/dist/client/StateClient.js +36 -0
  50. package/dist/client/StateClient.js.map +1 -0
  51. package/dist/client/TaskClient.d.ts +706 -0
  52. package/dist/client/TaskClient.d.ts.map +1 -0
  53. package/dist/client/TaskClient.js +2522 -0
  54. package/dist/client/TaskClient.js.map +1 -0
  55. package/dist/client/ToolClient.d.ts +278 -0
  56. package/dist/client/ToolClient.d.ts.map +1 -0
  57. package/dist/client/ToolClient.js +1139 -0
  58. package/dist/client/ToolClient.js.map +1 -0
  59. package/dist/client/a2a/index.d.ts +10 -0
  60. package/dist/client/a2a/index.d.ts.map +1 -0
  61. package/dist/client/a2a/index.js +9 -0
  62. package/dist/client/a2a/index.js.map +1 -0
  63. package/dist/client/a2a/registerA2A.d.ts +170 -0
  64. package/dist/client/a2a/registerA2A.d.ts.map +1 -0
  65. package/dist/client/a2a/registerA2A.js +85 -0
  66. package/dist/client/a2a/registerA2A.js.map +1 -0
  67. package/dist/client/connection.d.ts +893 -0
  68. package/dist/client/connection.d.ts.map +1 -0
  69. package/dist/client/connection.js +2189 -0
  70. package/dist/client/connection.js.map +1 -0
  71. package/dist/client/errors.d.ts +735 -0
  72. package/dist/client/errors.d.ts.map +1 -0
  73. package/dist/client/errors.js +921 -0
  74. package/dist/client/errors.js.map +1 -0
  75. package/dist/client/index.d.ts +26 -0
  76. package/dist/client/index.d.ts.map +1 -0
  77. package/dist/client/index.js +20 -0
  78. package/dist/client/index.js.map +1 -0
  79. package/dist/client/inlineGraph.d.ts +66 -0
  80. package/dist/client/inlineGraph.d.ts.map +1 -0
  81. package/dist/client/inlineGraph.js +500 -0
  82. package/dist/client/inlineGraph.js.map +1 -0
  83. package/dist/client/internal/thenable.d.ts +27 -0
  84. package/dist/client/internal/thenable.d.ts.map +1 -0
  85. package/dist/client/internal/thenable.js +31 -0
  86. package/dist/client/internal/thenable.js.map +1 -0
  87. package/dist/client/iterator.d.ts +32 -0
  88. package/dist/client/iterator.d.ts.map +1 -0
  89. package/dist/client/iterator.js +73 -0
  90. package/dist/client/iterator.js.map +1 -0
  91. package/dist/client/mcp/McpClientPool.browser.d.ts +76 -0
  92. package/dist/client/mcp/McpClientPool.browser.d.ts.map +1 -0
  93. package/dist/client/mcp/McpClientPool.browser.js +78 -0
  94. package/dist/client/mcp/McpClientPool.browser.js.map +1 -0
  95. package/dist/client/mcp/McpClientPool.d.ts +236 -0
  96. package/dist/client/mcp/McpClientPool.d.ts.map +1 -0
  97. package/dist/client/mcp/McpClientPool.js +585 -0
  98. package/dist/client/mcp/McpClientPool.js.map +1 -0
  99. package/dist/client/mcp/projection.d.ts +109 -0
  100. package/dist/client/mcp/projection.d.ts.map +1 -0
  101. package/dist/client/mcp/projection.js +446 -0
  102. package/dist/client/mcp/projection.js.map +1 -0
  103. package/dist/client/mcp/substituteEnv.browser.d.ts +18 -0
  104. package/dist/client/mcp/substituteEnv.browser.d.ts.map +1 -0
  105. package/dist/client/mcp/substituteEnv.browser.js +20 -0
  106. package/dist/client/mcp/substituteEnv.browser.js.map +1 -0
  107. package/dist/client/mcp/substituteEnv.d.ts +45 -0
  108. package/dist/client/mcp/substituteEnv.d.ts.map +1 -0
  109. package/dist/client/mcp/substituteEnv.js +63 -0
  110. package/dist/client/mcp/substituteEnv.js.map +1 -0
  111. package/dist/client/observers.d.ts +57 -0
  112. package/dist/client/observers.d.ts.map +1 -0
  113. package/dist/client/observers.js +203 -0
  114. package/dist/client/observers.js.map +1 -0
  115. package/dist/client/options.d.ts +269 -0
  116. package/dist/client/options.d.ts.map +1 -0
  117. package/dist/client/options.js +9 -0
  118. package/dist/client/options.js.map +1 -0
  119. package/dist/client/tools/_readlineApprovalPrompt.browser.d.ts +17 -0
  120. package/dist/client/tools/_readlineApprovalPrompt.browser.d.ts.map +1 -0
  121. package/dist/client/tools/_readlineApprovalPrompt.browser.js +24 -0
  122. package/dist/client/tools/_readlineApprovalPrompt.browser.js.map +1 -0
  123. package/dist/client/tools/_readlineApprovalPrompt.d.ts +33 -0
  124. package/dist/client/tools/_readlineApprovalPrompt.d.ts.map +1 -0
  125. package/dist/client/tools/_readlineApprovalPrompt.js +90 -0
  126. package/dist/client/tools/_readlineApprovalPrompt.js.map +1 -0
  127. package/dist/client/tools/approval.d.ts +280 -0
  128. package/dist/client/tools/approval.d.ts.map +1 -0
  129. package/dist/client/tools/approval.js +229 -0
  130. package/dist/client/tools/approval.js.map +1 -0
  131. package/dist/client/tools/bindFunctionToolDefs.d.ts +156 -0
  132. package/dist/client/tools/bindFunctionToolDefs.d.ts.map +1 -0
  133. package/dist/client/tools/bindFunctionToolDefs.js +360 -0
  134. package/dist/client/tools/bindFunctionToolDefs.js.map +1 -0
  135. package/dist/client/tools/defineFunctionTool.d.ts +277 -0
  136. package/dist/client/tools/defineFunctionTool.d.ts.map +1 -0
  137. package/dist/client/tools/defineFunctionTool.js +190 -0
  138. package/dist/client/tools/defineFunctionTool.js.map +1 -0
  139. package/dist/client/transport.browser.d.ts +20 -0
  140. package/dist/client/transport.browser.d.ts.map +1 -0
  141. package/dist/client/transport.browser.js +29 -0
  142. package/dist/client/transport.browser.js.map +1 -0
  143. package/dist/client/transport.d.ts +47 -0
  144. package/dist/client/transport.d.ts.map +1 -0
  145. package/dist/client/transport.js +102 -0
  146. package/dist/client/transport.js.map +1 -0
  147. package/dist/client/transport.shared.d.ts +30 -0
  148. package/dist/client/transport.shared.d.ts.map +1 -0
  149. package/dist/client/transport.shared.js +40 -0
  150. package/dist/client/transport.shared.js.map +1 -0
  151. package/dist/client/uuid.d.ts +32 -0
  152. package/dist/client/uuid.d.ts.map +1 -0
  153. package/dist/client/uuid.js +65 -0
  154. package/dist/client/uuid.js.map +1 -0
  155. package/dist/index.d.ts +88 -39
  156. package/dist/index.d.ts.map +1 -1
  157. package/dist/index.js +166 -43
  158. package/dist/index.js.map +1 -1
  159. package/dist/observability/attributes.d.ts +136 -0
  160. package/dist/observability/attributes.d.ts.map +1 -0
  161. package/dist/observability/attributes.js +184 -0
  162. package/dist/observability/attributes.js.map +1 -0
  163. package/dist/observability/index.d.ts +14 -0
  164. package/dist/observability/index.d.ts.map +1 -0
  165. package/dist/observability/index.js +11 -0
  166. package/dist/observability/index.js.map +1 -0
  167. package/dist/observability/resolveOTel.browser.d.ts +13 -0
  168. package/dist/observability/resolveOTel.browser.d.ts.map +1 -0
  169. package/dist/observability/resolveOTel.browser.js +14 -0
  170. package/dist/observability/resolveOTel.browser.js.map +1 -0
  171. package/dist/observability/resolveOTel.d.ts +28 -0
  172. package/dist/observability/resolveOTel.d.ts.map +1 -0
  173. package/dist/observability/resolveOTel.js +74 -0
  174. package/dist/observability/resolveOTel.js.map +1 -0
  175. package/dist/observability/spans.d.ts +198 -0
  176. package/dist/observability/spans.d.ts.map +1 -0
  177. package/dist/observability/spans.js +300 -0
  178. package/dist/observability/spans.js.map +1 -0
  179. package/dist/observability/traceContext.d.ts +51 -0
  180. package/dist/observability/traceContext.d.ts.map +1 -0
  181. package/dist/observability/traceContext.js +151 -0
  182. package/dist/observability/traceContext.js.map +1 -0
  183. package/dist/observability/transportMetrics.d.ts +58 -0
  184. package/dist/observability/transportMetrics.d.ts.map +1 -0
  185. package/dist/observability/transportMetrics.js +55 -0
  186. package/dist/observability/transportMetrics.js.map +1 -0
  187. package/dist/qar/agentSpec.d.ts +93 -0
  188. package/dist/qar/agentSpec.d.ts.map +1 -0
  189. package/dist/qar/agentSpec.js +184 -0
  190. package/dist/qar/agentSpec.js.map +1 -0
  191. package/dist/qar/clientEvents.d.ts +86 -0
  192. package/dist/qar/clientEvents.d.ts.map +1 -0
  193. package/dist/qar/clientEvents.js +36 -0
  194. package/dist/qar/clientEvents.js.map +1 -0
  195. package/dist/qar/envelopes.d.ts +227 -0
  196. package/dist/qar/envelopes.d.ts.map +1 -0
  197. package/dist/qar/envelopes.js +67 -0
  198. package/dist/qar/envelopes.js.map +1 -0
  199. package/dist/qar/generated/envelope.d.ts +332 -0
  200. package/dist/qar/generated/envelope.d.ts.map +1 -0
  201. package/dist/qar/generated/envelope.js +15 -0
  202. package/dist/qar/generated/envelope.js.map +1 -0
  203. package/dist/qar/generated/qar-info.d.ts +76 -0
  204. package/dist/qar/generated/qar-info.d.ts.map +1 -0
  205. package/dist/qar/generated/qar-info.js +15 -0
  206. package/dist/qar/generated/qar-info.js.map +1 -0
  207. package/dist/qar/generated/qodo-task-start-payload.d.ts +54 -0
  208. package/dist/qar/generated/qodo-task-start-payload.d.ts.map +1 -0
  209. package/dist/qar/generated/qodo-task-start-payload.js +15 -0
  210. package/dist/qar/generated/qodo-task-start-payload.js.map +1 -0
  211. package/dist/qar/ids.d.ts +19 -0
  212. package/dist/qar/ids.d.ts.map +1 -0
  213. package/dist/qar/ids.js +11 -0
  214. package/dist/qar/ids.js.map +1 -0
  215. package/dist/qar/index.d.ts +24 -0
  216. package/dist/qar/index.d.ts.map +1 -0
  217. package/dist/qar/index.js +16 -0
  218. package/dist/qar/index.js.map +1 -0
  219. package/dist/qar/info.d.ts +37 -0
  220. package/dist/qar/info.d.ts.map +1 -0
  221. package/dist/qar/info.js +17 -0
  222. package/dist/qar/info.js.map +1 -0
  223. package/dist/qar/json.d.ts +14 -0
  224. package/dist/qar/json.d.ts.map +1 -0
  225. package/dist/qar/json.js +9 -0
  226. package/dist/qar/json.js.map +1 -0
  227. package/dist/qar/payloads.d.ts +480 -0
  228. package/dist/qar/payloads.d.ts.map +1 -0
  229. package/dist/qar/payloads.js +37 -0
  230. package/dist/qar/payloads.js.map +1 -0
  231. package/dist/qar/specs.d.ts +604 -0
  232. package/dist/qar/specs.d.ts.map +1 -0
  233. package/dist/qar/specs.js +29 -0
  234. package/dist/qar/specs.js.map +1 -0
  235. package/dist/qar/taskEvents.d.ts +25 -0
  236. package/dist/qar/taskEvents.d.ts.map +1 -0
  237. package/dist/qar/taskEvents.js +22 -0
  238. package/dist/qar/taskEvents.js.map +1 -0
  239. package/dist/qar/trace.d.ts +12 -0
  240. package/dist/qar/trace.d.ts.map +1 -0
  241. package/dist/qar/trace.js +12 -0
  242. package/dist/qar/trace.js.map +1 -0
  243. package/dist/skills/activation.d.ts +177 -0
  244. package/dist/skills/activation.d.ts.map +1 -0
  245. package/dist/skills/activation.js +428 -0
  246. package/dist/skills/activation.js.map +1 -0
  247. package/dist/skills/cli/index.browser.d.ts +18 -0
  248. package/dist/skills/cli/index.browser.d.ts.map +1 -0
  249. package/dist/skills/cli/index.browser.js +27 -0
  250. package/dist/skills/cli/index.browser.js.map +1 -0
  251. package/dist/skills/cli/index.d.ts +37 -0
  252. package/dist/skills/cli/index.d.ts.map +1 -0
  253. package/dist/skills/cli/index.js +494 -0
  254. package/dist/skills/cli/index.js.map +1 -0
  255. package/dist/skills/events.d.ts +255 -0
  256. package/dist/skills/events.d.ts.map +1 -0
  257. package/dist/skills/events.js +224 -0
  258. package/dist/skills/events.js.map +1 -0
  259. package/dist/skills/index.d.ts +45 -0
  260. package/dist/skills/index.d.ts.map +1 -0
  261. package/dist/skills/index.js +34 -0
  262. package/dist/skills/index.js.map +1 -0
  263. package/dist/skills/inject.d.ts +57 -0
  264. package/dist/skills/inject.d.ts.map +1 -0
  265. package/dist/skills/inject.js +162 -0
  266. package/dist/skills/inject.js.map +1 -0
  267. package/dist/skills/lockfile.browser.d.ts +56 -0
  268. package/dist/skills/lockfile.browser.d.ts.map +1 -0
  269. package/dist/skills/lockfile.browser.js +55 -0
  270. package/dist/skills/lockfile.browser.js.map +1 -0
  271. package/dist/skills/lockfile.d.ts +137 -0
  272. package/dist/skills/lockfile.d.ts.map +1 -0
  273. package/dist/skills/lockfile.js +423 -0
  274. package/dist/skills/lockfile.js.map +1 -0
  275. package/dist/skills/manager.browser.d.ts +94 -0
  276. package/dist/skills/manager.browser.d.ts.map +1 -0
  277. package/dist/skills/manager.browser.js +159 -0
  278. package/dist/skills/manager.browser.js.map +1 -0
  279. package/dist/skills/manager.d.ts +362 -0
  280. package/dist/skills/manager.d.ts.map +1 -0
  281. package/dist/skills/manager.js +1386 -0
  282. package/dist/skills/manager.js.map +1 -0
  283. package/dist/skills/mcp/index.d.ts +15 -0
  284. package/dist/skills/mcp/index.d.ts.map +1 -0
  285. package/dist/skills/mcp/index.js +12 -0
  286. package/dist/skills/mcp/index.js.map +1 -0
  287. package/dist/skills/mcp/path.browser.d.ts +27 -0
  288. package/dist/skills/mcp/path.browser.d.ts.map +1 -0
  289. package/dist/skills/mcp/path.browser.js +33 -0
  290. package/dist/skills/mcp/path.browser.js.map +1 -0
  291. package/dist/skills/mcp/path.d.ts +57 -0
  292. package/dist/skills/mcp/path.d.ts.map +1 -0
  293. package/dist/skills/mcp/path.js +150 -0
  294. package/dist/skills/mcp/path.js.map +1 -0
  295. package/dist/skills/mcp/server.browser.d.ts +32 -0
  296. package/dist/skills/mcp/server.browser.d.ts.map +1 -0
  297. package/dist/skills/mcp/server.browser.js +53 -0
  298. package/dist/skills/mcp/server.browser.js.map +1 -0
  299. package/dist/skills/mcp/server.d.ts +144 -0
  300. package/dist/skills/mcp/server.d.ts.map +1 -0
  301. package/dist/skills/mcp/server.js +841 -0
  302. package/dist/skills/mcp/server.js.map +1 -0
  303. package/dist/skills/mcp/types.d.ts +72 -0
  304. package/dist/skills/mcp/types.d.ts.map +1 -0
  305. package/dist/skills/mcp/types.js +20 -0
  306. package/dist/skills/mcp/types.js.map +1 -0
  307. package/dist/skills/mcp/wireDefs.d.ts +58 -0
  308. package/dist/skills/mcp/wireDefs.d.ts.map +1 -0
  309. package/dist/skills/mcp/wireDefs.js +141 -0
  310. package/dist/skills/mcp/wireDefs.js.map +1 -0
  311. package/dist/skills/parser.d.ts +63 -0
  312. package/dist/skills/parser.d.ts.map +1 -0
  313. package/dist/skills/parser.js +755 -0
  314. package/dist/skills/parser.js.map +1 -0
  315. package/dist/skills/prefilter.d.ts +104 -0
  316. package/dist/skills/prefilter.d.ts.map +1 -0
  317. package/dist/skills/prefilter.js +398 -0
  318. package/dist/skills/prefilter.js.map +1 -0
  319. package/dist/skills/preprocess.d.ts +169 -0
  320. package/dist/skills/preprocess.d.ts.map +1 -0
  321. package/dist/skills/preprocess.js +535 -0
  322. package/dist/skills/preprocess.js.map +1 -0
  323. package/dist/skills/render.d.ts +83 -0
  324. package/dist/skills/render.d.ts.map +1 -0
  325. package/dist/skills/render.js +397 -0
  326. package/dist/skills/render.js.map +1 -0
  327. package/dist/skills/sources/index.browser.d.ts +29 -0
  328. package/dist/skills/sources/index.browser.d.ts.map +1 -0
  329. package/dist/skills/sources/index.browser.js +16 -0
  330. package/dist/skills/sources/index.browser.js.map +1 -0
  331. package/dist/skills/sources/index.d.ts +59 -0
  332. package/dist/skills/sources/index.d.ts.map +1 -0
  333. package/dist/skills/sources/index.js +471 -0
  334. package/dist/skills/sources/index.js.map +1 -0
  335. package/dist/skills/sources/walk.browser.d.ts +17 -0
  336. package/dist/skills/sources/walk.browser.d.ts.map +1 -0
  337. package/dist/skills/sources/walk.browser.js +19 -0
  338. package/dist/skills/sources/walk.browser.js.map +1 -0
  339. package/dist/skills/sources/walk.d.ts +68 -0
  340. package/dist/skills/sources/walk.d.ts.map +1 -0
  341. package/dist/skills/sources/walk.js +264 -0
  342. package/dist/skills/sources/walk.js.map +1 -0
  343. package/dist/skills/substitute.d.ts +87 -0
  344. package/dist/skills/substitute.d.ts.map +1 -0
  345. package/dist/skills/substitute.js +322 -0
  346. package/dist/skills/substitute.js.map +1 -0
  347. package/dist/skills/testing/SkillKit.browser.d.ts +62 -0
  348. package/dist/skills/testing/SkillKit.browser.d.ts.map +1 -0
  349. package/dist/skills/testing/SkillKit.browser.js +41 -0
  350. package/dist/skills/testing/SkillKit.browser.js.map +1 -0
  351. package/dist/skills/testing/SkillKit.d.ts +130 -0
  352. package/dist/skills/testing/SkillKit.d.ts.map +1 -0
  353. package/dist/skills/testing/SkillKit.js +316 -0
  354. package/dist/skills/testing/SkillKit.js.map +1 -0
  355. package/dist/skills/testing/index.d.ts +9 -0
  356. package/dist/skills/testing/index.d.ts.map +1 -0
  357. package/dist/skills/testing/index.js +8 -0
  358. package/dist/skills/testing/index.js.map +1 -0
  359. package/dist/skills/trust.d.ts +72 -0
  360. package/dist/skills/trust.d.ts.map +1 -0
  361. package/dist/skills/trust.js +183 -0
  362. package/dist/skills/trust.js.map +1 -0
  363. package/dist/skills/types.d.ts +627 -0
  364. package/dist/skills/types.d.ts.map +1 -0
  365. package/dist/skills/types.js +85 -0
  366. package/dist/skills/types.js.map +1 -0
  367. package/dist/skills/validator.d.ts +95 -0
  368. package/dist/skills/validator.d.ts.map +1 -0
  369. package/dist/skills/validator.js +486 -0
  370. package/dist/skills/validator.js.map +1 -0
  371. package/dist/tracing/PipelineTracer.d.ts +35 -22
  372. package/dist/tracing/PipelineTracer.d.ts.map +1 -1
  373. package/dist/tracing/PipelineTracer.js +106 -61
  374. package/dist/tracing/PipelineTracer.js.map +1 -1
  375. package/dist/tracing/SdkTracer.d.ts +63 -61
  376. package/dist/tracing/SdkTracer.d.ts.map +1 -1
  377. package/dist/tracing/SdkTracer.js +185 -177
  378. package/dist/tracing/SdkTracer.js.map +1 -1
  379. package/dist/tracing/index.d.ts +10 -1
  380. package/dist/tracing/index.d.ts.map +1 -1
  381. package/dist/tracing/index.js +9 -0
  382. package/dist/tracing/index.js.map +1 -1
  383. package/dist/tracing/types.d.ts +89 -16
  384. package/dist/tracing/types.d.ts.map +1 -1
  385. package/dist/tracing/types.js +17 -4
  386. package/dist/tracing/types.js.map +1 -1
  387. package/dist/types.d.ts +6 -1
  388. package/dist/types.d.ts.map +1 -1
  389. package/dist/types.js +4 -0
  390. package/dist/types.js.map +1 -1
  391. package/dist/version.d.ts.map +1 -1
  392. package/dist/version.js +10 -20
  393. package/dist/version.js.map +1 -1
  394. package/package.json +53 -39
  395. package/.claude/skills/qodo-agent/SKILL.md +0 -974
  396. package/.claude/skills/qodo-agent/assets/programmatic-agent.ts +0 -407
  397. package/.claude/skills/qodo-agent/references/builtin-tools.md +0 -342
  398. package/.claude/skills/qodo-agent/references/common-issues.md +0 -537
  399. package/bin/rg +0 -0
  400. package/dist/api/agent.d.ts +0 -105
  401. package/dist/api/agent.d.ts.map +0 -1
  402. package/dist/api/agent.js +0 -963
  403. package/dist/api/agent.js.map +0 -1
  404. package/dist/api/analytics.d.ts +0 -43
  405. package/dist/api/analytics.d.ts.map +0 -1
  406. package/dist/api/analytics.js +0 -163
  407. package/dist/api/analytics.js.map +0 -1
  408. package/dist/api/http.d.ts +0 -5
  409. package/dist/api/http.d.ts.map +0 -1
  410. package/dist/api/http.js +0 -62
  411. package/dist/api/http.js.map +0 -1
  412. package/dist/api/index.d.ts +0 -12
  413. package/dist/api/index.d.ts.map +0 -1
  414. package/dist/api/index.js +0 -17
  415. package/dist/api/index.js.map +0 -1
  416. package/dist/api/taskTracking.d.ts +0 -54
  417. package/dist/api/taskTracking.d.ts.map +0 -1
  418. package/dist/api/taskTracking.js +0 -208
  419. package/dist/api/taskTracking.js.map +0 -1
  420. package/dist/api/types.d.ts +0 -93
  421. package/dist/api/types.d.ts.map +0 -1
  422. package/dist/api/types.js +0 -2
  423. package/dist/api/types.js.map +0 -1
  424. package/dist/api/utils.d.ts +0 -8
  425. package/dist/api/utils.d.ts.map +0 -1
  426. package/dist/api/utils.js +0 -63
  427. package/dist/api/utils.js.map +0 -1
  428. package/dist/api/websocket.d.ts +0 -203
  429. package/dist/api/websocket.d.ts.map +0 -1
  430. package/dist/api/websocket.js +0 -1166
  431. package/dist/api/websocket.js.map +0 -1
  432. package/dist/bin/install-skill.d.ts +0 -14
  433. package/dist/bin/install-skill.d.ts.map +0 -1
  434. package/dist/bin/install-skill.js +0 -125
  435. package/dist/bin/install-skill.js.map +0 -1
  436. package/dist/bin/run-helpers.d.ts +0 -34
  437. package/dist/bin/run-helpers.d.ts.map +0 -1
  438. package/dist/bin/run-helpers.js +0 -186
  439. package/dist/bin/run-helpers.js.map +0 -1
  440. package/dist/bin/run.d.ts +0 -13
  441. package/dist/bin/run.d.ts.map +0 -1
  442. package/dist/bin/run.js +0 -57
  443. package/dist/bin/run.js.map +0 -1
  444. package/dist/clients/index.d.ts +0 -10
  445. package/dist/clients/index.d.ts.map +0 -1
  446. package/dist/clients/index.js +0 -8
  447. package/dist/clients/index.js.map +0 -1
  448. package/dist/clients/info/InfoClient.d.ts +0 -37
  449. package/dist/clients/info/InfoClient.d.ts.map +0 -1
  450. package/dist/clients/info/InfoClient.js +0 -69
  451. package/dist/clients/info/InfoClient.js.map +0 -1
  452. package/dist/clients/info/index.d.ts +0 -4
  453. package/dist/clients/info/index.d.ts.map +0 -1
  454. package/dist/clients/info/index.js +0 -2
  455. package/dist/clients/info/index.js.map +0 -1
  456. package/dist/clients/info/types.d.ts +0 -21
  457. package/dist/clients/info/types.d.ts.map +0 -1
  458. package/dist/clients/info/types.js +0 -2
  459. package/dist/clients/info/types.js.map +0 -1
  460. package/dist/clients/sessions/SessionsClient.d.ts +0 -34
  461. package/dist/clients/sessions/SessionsClient.d.ts.map +0 -1
  462. package/dist/clients/sessions/SessionsClient.js +0 -71
  463. package/dist/clients/sessions/SessionsClient.js.map +0 -1
  464. package/dist/clients/sessions/index.d.ts +0 -4
  465. package/dist/clients/sessions/index.d.ts.map +0 -1
  466. package/dist/clients/sessions/index.js +0 -2
  467. package/dist/clients/sessions/index.js.map +0 -1
  468. package/dist/clients/sessions/types.d.ts +0 -20
  469. package/dist/clients/sessions/types.d.ts.map +0 -1
  470. package/dist/clients/sessions/types.js +0 -2
  471. package/dist/clients/sessions/types.js.map +0 -1
  472. package/dist/clients/tools/ToolsClient.d.ts +0 -39
  473. package/dist/clients/tools/ToolsClient.d.ts.map +0 -1
  474. package/dist/clients/tools/ToolsClient.js +0 -95
  475. package/dist/clients/tools/ToolsClient.js.map +0 -1
  476. package/dist/clients/tools/index.d.ts +0 -4
  477. package/dist/clients/tools/index.d.ts.map +0 -1
  478. package/dist/clients/tools/index.js +0 -2
  479. package/dist/clients/tools/index.js.map +0 -1
  480. package/dist/clients/tools/types.d.ts +0 -14
  481. package/dist/clients/tools/types.d.ts.map +0 -1
  482. package/dist/clients/tools/types.js +0 -2
  483. package/dist/clients/tools/types.js.map +0 -1
  484. package/dist/config/ConfigManager.d.ts +0 -43
  485. package/dist/config/ConfigManager.d.ts.map +0 -1
  486. package/dist/config/ConfigManager.js +0 -472
  487. package/dist/config/ConfigManager.js.map +0 -1
  488. package/dist/config/index.d.ts +0 -6
  489. package/dist/config/index.d.ts.map +0 -1
  490. package/dist/config/index.js +0 -7
  491. package/dist/config/index.js.map +0 -1
  492. package/dist/config/urlConfig.d.ts +0 -15
  493. package/dist/config/urlConfig.d.ts.map +0 -1
  494. package/dist/config/urlConfig.js +0 -75
  495. package/dist/config/urlConfig.js.map +0 -1
  496. package/dist/constants/errors.d.ts +0 -2
  497. package/dist/constants/errors.d.ts.map +0 -1
  498. package/dist/constants/errors.js +0 -2
  499. package/dist/constants/errors.js.map +0 -1
  500. package/dist/constants/index.d.ts +0 -7
  501. package/dist/constants/index.d.ts.map +0 -1
  502. package/dist/constants/index.js +0 -11
  503. package/dist/constants/index.js.map +0 -1
  504. package/dist/constants/tools.d.ts +0 -4
  505. package/dist/constants/tools.d.ts.map +0 -1
  506. package/dist/constants/tools.js +0 -4
  507. package/dist/constants/tools.js.map +0 -1
  508. package/dist/constants/versions.d.ts +0 -2
  509. package/dist/constants/versions.d.ts.map +0 -1
  510. package/dist/constants/versions.js +0 -2
  511. package/dist/constants/versions.js.map +0 -1
  512. package/dist/context/buildUserContext.d.ts +0 -18
  513. package/dist/context/buildUserContext.d.ts.map +0 -1
  514. package/dist/context/buildUserContext.js +0 -34
  515. package/dist/context/buildUserContext.js.map +0 -1
  516. package/dist/context/index.d.ts +0 -9
  517. package/dist/context/index.d.ts.map +0 -1
  518. package/dist/context/index.js +0 -9
  519. package/dist/context/index.js.map +0 -1
  520. package/dist/context/messageManager.d.ts +0 -42
  521. package/dist/context/messageManager.d.ts.map +0 -1
  522. package/dist/context/messageManager.js +0 -322
  523. package/dist/context/messageManager.js.map +0 -1
  524. package/dist/context/taskFocus.d.ts +0 -2
  525. package/dist/context/taskFocus.d.ts.map +0 -1
  526. package/dist/context/taskFocus.js +0 -26
  527. package/dist/context/taskFocus.js.map +0 -1
  528. package/dist/context/userInput.d.ts +0 -3
  529. package/dist/context/userInput.d.ts.map +0 -1
  530. package/dist/context/userInput.js +0 -20
  531. package/dist/context/userInput.js.map +0 -1
  532. package/dist/mcp/MCPManager.d.ts +0 -109
  533. package/dist/mcp/MCPManager.d.ts.map +0 -1
  534. package/dist/mcp/MCPManager.js +0 -592
  535. package/dist/mcp/MCPManager.js.map +0 -1
  536. package/dist/mcp/approvedTools.d.ts +0 -4
  537. package/dist/mcp/approvedTools.d.ts.map +0 -1
  538. package/dist/mcp/approvedTools.js +0 -19
  539. package/dist/mcp/approvedTools.js.map +0 -1
  540. package/dist/mcp/baseServer.d.ts +0 -75
  541. package/dist/mcp/baseServer.d.ts.map +0 -1
  542. package/dist/mcp/baseServer.js +0 -107
  543. package/dist/mcp/baseServer.js.map +0 -1
  544. package/dist/mcp/builtinServers.d.ts +0 -15
  545. package/dist/mcp/builtinServers.d.ts.map +0 -1
  546. package/dist/mcp/builtinServers.js +0 -141
  547. package/dist/mcp/builtinServers.js.map +0 -1
  548. package/dist/mcp/dynamicBEServer.d.ts +0 -20
  549. package/dist/mcp/dynamicBEServer.d.ts.map +0 -1
  550. package/dist/mcp/dynamicBEServer.js +0 -52
  551. package/dist/mcp/dynamicBEServer.js.map +0 -1
  552. package/dist/mcp/index.d.ts +0 -18
  553. package/dist/mcp/index.d.ts.map +0 -1
  554. package/dist/mcp/index.js +0 -23
  555. package/dist/mcp/index.js.map +0 -1
  556. package/dist/mcp/mcpInitialization.d.ts +0 -2
  557. package/dist/mcp/mcpInitialization.d.ts.map +0 -1
  558. package/dist/mcp/mcpInitialization.js +0 -56
  559. package/dist/mcp/mcpInitialization.js.map +0 -1
  560. package/dist/mcp/servers/filesystem.d.ts +0 -44
  561. package/dist/mcp/servers/filesystem.d.ts.map +0 -1
  562. package/dist/mcp/servers/filesystem.js +0 -776
  563. package/dist/mcp/servers/filesystem.js.map +0 -1
  564. package/dist/mcp/servers/git.d.ts +0 -18
  565. package/dist/mcp/servers/git.d.ts.map +0 -1
  566. package/dist/mcp/servers/git.js +0 -441
  567. package/dist/mcp/servers/git.js.map +0 -1
  568. package/dist/mcp/servers/ripgrep.d.ts +0 -39
  569. package/dist/mcp/servers/ripgrep.d.ts.map +0 -1
  570. package/dist/mcp/servers/ripgrep.js +0 -550
  571. package/dist/mcp/servers/ripgrep.js.map +0 -1
  572. package/dist/mcp/servers/shell.d.ts +0 -20
  573. package/dist/mcp/servers/shell.d.ts.map +0 -1
  574. package/dist/mcp/servers/shell.js +0 -519
  575. package/dist/mcp/servers/shell.js.map +0 -1
  576. package/dist/mcp/serversRegistry.d.ts +0 -55
  577. package/dist/mcp/serversRegistry.d.ts.map +0 -1
  578. package/dist/mcp/serversRegistry.js +0 -416
  579. package/dist/mcp/serversRegistry.js.map +0 -1
  580. package/dist/mcp/toolProcessor.d.ts +0 -82
  581. package/dist/mcp/toolProcessor.d.ts.map +0 -1
  582. package/dist/mcp/toolProcessor.js +0 -392
  583. package/dist/mcp/toolProcessor.js.map +0 -1
  584. package/dist/mcp/types.d.ts +0 -29
  585. package/dist/mcp/types.d.ts.map +0 -1
  586. package/dist/mcp/types.js +0 -2
  587. package/dist/mcp/types.js.map +0 -1
  588. package/dist/messages/index.d.ts +0 -8
  589. package/dist/messages/index.d.ts.map +0 -1
  590. package/dist/messages/index.js +0 -7
  591. package/dist/messages/index.js.map +0 -1
  592. package/dist/messages/openai.d.ts +0 -26
  593. package/dist/messages/openai.d.ts.map +0 -1
  594. package/dist/messages/openai.js +0 -55
  595. package/dist/messages/openai.js.map +0 -1
  596. package/dist/messages/types.d.ts +0 -73
  597. package/dist/messages/types.d.ts.map +0 -1
  598. package/dist/messages/types.js +0 -78
  599. package/dist/messages/types.js.map +0 -1
  600. package/dist/parser/index.d.ts +0 -72
  601. package/dist/parser/index.d.ts.map +0 -1
  602. package/dist/parser/index.js +0 -967
  603. package/dist/parser/index.js.map +0 -1
  604. package/dist/parser/types.d.ts +0 -153
  605. package/dist/parser/types.d.ts.map +0 -1
  606. package/dist/parser/types.js +0 -6
  607. package/dist/parser/types.js.map +0 -1
  608. package/dist/parser/utils.d.ts +0 -18
  609. package/dist/parser/utils.d.ts.map +0 -1
  610. package/dist/parser/utils.js +0 -64
  611. package/dist/parser/utils.js.map +0 -1
  612. package/dist/sdk/QodoSDK.d.ts +0 -218
  613. package/dist/sdk/QodoSDK.d.ts.map +0 -1
  614. package/dist/sdk/QodoSDK.js +0 -1115
  615. package/dist/sdk/QodoSDK.js.map +0 -1
  616. package/dist/sdk/artifacts.d.ts +0 -156
  617. package/dist/sdk/artifacts.d.ts.map +0 -1
  618. package/dist/sdk/artifacts.js +0 -166
  619. package/dist/sdk/artifacts.js.map +0 -1
  620. package/dist/sdk/bootstrap.d.ts +0 -16
  621. package/dist/sdk/bootstrap.d.ts.map +0 -1
  622. package/dist/sdk/bootstrap.js +0 -28
  623. package/dist/sdk/bootstrap.js.map +0 -1
  624. package/dist/sdk/builders.d.ts +0 -54
  625. package/dist/sdk/builders.d.ts.map +0 -1
  626. package/dist/sdk/builders.js +0 -117
  627. package/dist/sdk/builders.js.map +0 -1
  628. package/dist/sdk/defaults.d.ts +0 -11
  629. package/dist/sdk/defaults.d.ts.map +0 -1
  630. package/dist/sdk/defaults.js +0 -39
  631. package/dist/sdk/defaults.js.map +0 -1
  632. package/dist/sdk/discovery.d.ts +0 -2
  633. package/dist/sdk/discovery.d.ts.map +0 -1
  634. package/dist/sdk/discovery.js +0 -25
  635. package/dist/sdk/discovery.js.map +0 -1
  636. package/dist/sdk/events.d.ts +0 -269
  637. package/dist/sdk/events.d.ts.map +0 -1
  638. package/dist/sdk/events.js +0 -69
  639. package/dist/sdk/events.js.map +0 -1
  640. package/dist/sdk/exit-expression.d.ts +0 -13
  641. package/dist/sdk/exit-expression.d.ts.map +0 -1
  642. package/dist/sdk/exit-expression.js +0 -35
  643. package/dist/sdk/exit-expression.js.map +0 -1
  644. package/dist/sdk/index.d.ts +0 -17
  645. package/dist/sdk/index.d.ts.map +0 -1
  646. package/dist/sdk/index.js +0 -17
  647. package/dist/sdk/index.js.map +0 -1
  648. package/dist/sdk/middleware.d.ts +0 -59
  649. package/dist/sdk/middleware.d.ts.map +0 -1
  650. package/dist/sdk/middleware.js +0 -69
  651. package/dist/sdk/middleware.js.map +0 -1
  652. package/dist/sdk/pipeline/PipelineBuilder.d.ts +0 -79
  653. package/dist/sdk/pipeline/PipelineBuilder.d.ts.map +0 -1
  654. package/dist/sdk/pipeline/PipelineBuilder.js +0 -129
  655. package/dist/sdk/pipeline/PipelineBuilder.js.map +0 -1
  656. package/dist/sdk/pipeline/PipelineRunner.d.ts +0 -28
  657. package/dist/sdk/pipeline/PipelineRunner.d.ts.map +0 -1
  658. package/dist/sdk/pipeline/PipelineRunner.js +0 -326
  659. package/dist/sdk/pipeline/PipelineRunner.js.map +0 -1
  660. package/dist/sdk/pipeline/compiler.d.ts +0 -24
  661. package/dist/sdk/pipeline/compiler.d.ts.map +0 -1
  662. package/dist/sdk/pipeline/compiler.js +0 -199
  663. package/dist/sdk/pipeline/compiler.js.map +0 -1
  664. package/dist/sdk/pipeline/declarative.d.ts +0 -34
  665. package/dist/sdk/pipeline/declarative.d.ts.map +0 -1
  666. package/dist/sdk/pipeline/declarative.js +0 -9
  667. package/dist/sdk/pipeline/declarative.js.map +0 -1
  668. package/dist/sdk/pipeline/index.d.ts +0 -20
  669. package/dist/sdk/pipeline/index.d.ts.map +0 -1
  670. package/dist/sdk/pipeline/index.js +0 -19
  671. package/dist/sdk/pipeline/index.js.map +0 -1
  672. package/dist/sdk/pipeline/types.d.ts +0 -93
  673. package/dist/sdk/pipeline/types.d.ts.map +0 -1
  674. package/dist/sdk/pipeline/types.js +0 -10
  675. package/dist/sdk/pipeline/types.js.map +0 -1
  676. package/dist/sdk/policies.d.ts +0 -163
  677. package/dist/sdk/policies.d.ts.map +0 -1
  678. package/dist/sdk/policies.js +0 -243
  679. package/dist/sdk/policies.js.map +0 -1
  680. package/dist/sdk/runner/AgentRunner.d.ts +0 -22
  681. package/dist/sdk/runner/AgentRunner.d.ts.map +0 -1
  682. package/dist/sdk/runner/AgentRunner.js +0 -222
  683. package/dist/sdk/runner/AgentRunner.js.map +0 -1
  684. package/dist/sdk/runner/finalize.d.ts +0 -56
  685. package/dist/sdk/runner/finalize.d.ts.map +0 -1
  686. package/dist/sdk/runner/finalize.js +0 -155
  687. package/dist/sdk/runner/finalize.js.map +0 -1
  688. package/dist/sdk/runner/formats.d.ts +0 -7
  689. package/dist/sdk/runner/formats.d.ts.map +0 -1
  690. package/dist/sdk/runner/formats.js +0 -76
  691. package/dist/sdk/runner/formats.js.map +0 -1
  692. package/dist/sdk/runner/index.d.ts +0 -9
  693. package/dist/sdk/runner/index.d.ts.map +0 -1
  694. package/dist/sdk/runner/index.js +0 -9
  695. package/dist/sdk/runner/index.js.map +0 -1
  696. package/dist/sdk/runner/progress.d.ts +0 -3
  697. package/dist/sdk/runner/progress.d.ts.map +0 -1
  698. package/dist/sdk/runner/progress.js +0 -16
  699. package/dist/sdk/runner/progress.js.map +0 -1
  700. package/dist/sdk/schemas.d.ts +0 -72
  701. package/dist/sdk/schemas.d.ts.map +0 -1
  702. package/dist/sdk/schemas.js +0 -282
  703. package/dist/sdk/schemas.js.map +0 -1
  704. package/dist/sdk/trigger-context.d.ts +0 -24
  705. package/dist/sdk/trigger-context.d.ts.map +0 -1
  706. package/dist/sdk/trigger-context.js +0 -136
  707. package/dist/sdk/trigger-context.js.map +0 -1
  708. package/dist/session/SessionContext.d.ts +0 -89
  709. package/dist/session/SessionContext.d.ts.map +0 -1
  710. package/dist/session/SessionContext.js +0 -410
  711. package/dist/session/SessionContext.js.map +0 -1
  712. package/dist/session/environment.d.ts +0 -52
  713. package/dist/session/environment.d.ts.map +0 -1
  714. package/dist/session/environment.js +0 -27
  715. package/dist/session/environment.js.map +0 -1
  716. package/dist/session/history.d.ts +0 -18
  717. package/dist/session/history.d.ts.map +0 -1
  718. package/dist/session/history.js +0 -68
  719. package/dist/session/history.js.map +0 -1
  720. package/dist/session/index.d.ts +0 -10
  721. package/dist/session/index.d.ts.map +0 -1
  722. package/dist/session/index.js +0 -9
  723. package/dist/session/index.js.map +0 -1
  724. package/dist/session/serverData.d.ts +0 -38
  725. package/dist/session/serverData.d.ts.map +0 -1
  726. package/dist/session/serverData.js +0 -261
  727. package/dist/session/serverData.js.map +0 -1
  728. package/dist/tracing/pipelineHelpers.d.ts +0 -29
  729. package/dist/tracing/pipelineHelpers.d.ts.map +0 -1
  730. package/dist/tracing/pipelineHelpers.js +0 -224
  731. package/dist/tracing/pipelineHelpers.js.map +0 -1
  732. package/dist/tracking/Tracker.d.ts +0 -55
  733. package/dist/tracking/Tracker.d.ts.map +0 -1
  734. package/dist/tracking/Tracker.js +0 -217
  735. package/dist/tracking/Tracker.js.map +0 -1
  736. package/dist/tracking/index.d.ts +0 -8
  737. package/dist/tracking/index.d.ts.map +0 -1
  738. package/dist/tracking/index.js +0 -8
  739. package/dist/tracking/index.js.map +0 -1
  740. package/dist/tracking/schemas.d.ts +0 -292
  741. package/dist/tracking/schemas.d.ts.map +0 -1
  742. package/dist/tracking/schemas.js +0 -91
  743. package/dist/tracking/schemas.js.map +0 -1
  744. package/dist/utils/extractSetFlags.d.ts +0 -6
  745. package/dist/utils/extractSetFlags.d.ts.map +0 -1
  746. package/dist/utils/extractSetFlags.js +0 -16
  747. package/dist/utils/extractSetFlags.js.map +0 -1
  748. package/dist/utils/formatTimeAgo.d.ts +0 -2
  749. package/dist/utils/formatTimeAgo.d.ts.map +0 -1
  750. package/dist/utils/formatTimeAgo.js +0 -20
  751. package/dist/utils/formatTimeAgo.js.map +0 -1
  752. package/dist/utils/index.d.ts +0 -12
  753. package/dist/utils/index.d.ts.map +0 -1
  754. package/dist/utils/index.js +0 -12
  755. package/dist/utils/index.js.map +0 -1
  756. package/dist/utils/machineId.d.ts +0 -14
  757. package/dist/utils/machineId.d.ts.map +0 -1
  758. package/dist/utils/machineId.js +0 -66
  759. package/dist/utils/machineId.js.map +0 -1
  760. package/dist/utils/pathUtils.d.ts +0 -22
  761. package/dist/utils/pathUtils.d.ts.map +0 -1
  762. package/dist/utils/pathUtils.js +0 -54
  763. package/dist/utils/pathUtils.js.map +0 -1
  764. package/scripts/download-ripgrep.js +0 -269
@@ -0,0 +1,893 @@
1
+ /**
2
+ * `Connection` — owns the WebSocket, multiplexes inbound envelopes onto
3
+ * subscriptions, encodes outbound envelopes.
4
+ *
5
+ * One `Connection` per `QodoClient.connect()` call. `tasks.start` /
6
+ * `tasks.continue` register a `TaskSubscription`; `client.receive()` registers
7
+ * a raw subscription that taps every inbound envelope. The connection routes
8
+ * inbound envelopes to subscriptions whose `parent_message_id` chain matches.
9
+ *
10
+ * **Reconnect + replay.** The Connection survives transport drops:
11
+ * subscriptions stay alive while the underlying `WSTransport` is replaced via
12
+ * the same factory. On a fresh transport, every active task subscription's
13
+ * `task_id` + `lastSeenMessageId` is sent back to the server as a
14
+ * `task.resubscribe` envelope; the server replays anything after that anchor
15
+ * from its per-session ring buffer (cap 1000 envelopes per session). No
16
+ * client-side outbox — durability is server-side. The 1.x `OutboxTurn` /
17
+ * `Resume` / `ResumeAck` machinery does not exist here.
18
+ */
19
+ import type { Envelope } from '../qar/envelopes.js';
20
+ import type { MessageId, SessionId, TaskId, ToolCallId } from '../qar/ids.js';
21
+ import type { TaskEvent } from '../qar/taskEvents.js';
22
+ import type { ClientEvent } from '../qar/clientEvents.js';
23
+ import type { SessionState, TaskCancelPayload, TaskContinuePayload, TaskForceResumePayload, TaskResubscribePayload, TaskStartPayload, ToolResponsePayload } from '../qar/payloads.js';
24
+ import type { ClientReconnectOptions } from './options.js';
25
+ import { TraceContextProvider } from '../observability/traceContext.js';
26
+ import type { SpanLifecycle } from '../observability/spans.js';
27
+ import { TransportMetrics } from '../observability/transportMetrics.js';
28
+ import type { WSTransportFactory, WSTransportFactoryArgs } from './transport.js';
29
+ /**
30
+ * Outbound envelopes the SDK constructs.
31
+ */
32
+ type OutboundPayload = {
33
+ readonly kind: 'task.start';
34
+ readonly payload: TaskStartPayload;
35
+ } | {
36
+ readonly kind: 'task.continue';
37
+ readonly payload: TaskContinuePayload;
38
+ } | {
39
+ readonly kind: 'task.cancel';
40
+ readonly payload: TaskCancelPayload;
41
+ } | {
42
+ readonly kind: 'task.resubscribe';
43
+ readonly payload: TaskResubscribePayload;
44
+ } | {
45
+ readonly kind: 'task.forceResume';
46
+ readonly payload: TaskForceResumePayload;
47
+ } | {
48
+ readonly kind: 'tool.response';
49
+ readonly payload: ToolResponsePayload;
50
+ };
51
+ /**
52
+ * A subscription on the inbound stream. The connection calls `consider` for
53
+ * every inbound envelope; the subscription returns `true` if it absorbed the
54
+ * envelope (so terminal envelopes don't double-fire elsewhere) and pushes the
55
+ * envelope to its consumer.
56
+ *
57
+ * `task.resubscribe` and tool tunneling plug in via this shape too, so
58
+ * the routing fabric is shared.
59
+ */
60
+ export interface InboundSubscription {
61
+ /**
62
+ * Called for every inbound envelope. Returns `true` if this subscription
63
+ * consumed the envelope (used so the connection knows it was routed to at
64
+ * least one task subscriber). Subscriptions are independent — a `tool.request`
65
+ * may belong to a task subscription AND surface on the raw `receive()` tap.
66
+ */
67
+ consider(env: Envelope): boolean;
68
+ /**
69
+ * Push a synthetic SDK-internal `qar.client.*` event onto the consumer's
70
+ * iterator. Distinct from `consider` because client events are not
71
+ * envelopes — they have no `message_id` / `session_id` / `payload`.
72
+ */
73
+ considerClient(ev: ClientEvent): void;
74
+ /** Called when the underlying transport fails. Subscription should fail its consumer. */
75
+ fail(err: Error): void;
76
+ /** Called when the connection closes cleanly. Subscription should close its consumer. */
77
+ close(): void;
78
+ }
79
+ /**
80
+ * Argument shape for the `task.started` resolver. Includes the
81
+ * idempotent-admission fields when the ack reports an existing session
82
+ * (`isNew === false`) or a terminal re-dispatch (`previousTaskId` +
83
+ * `previousState` populated). Old SDK call sites that ignore the new
84
+ * fields keep working — only callers exposing the full
85
+ * `TaskAdmissionResult` Promise on `TaskStartIterable` need them.
86
+ */
87
+ export interface TaskStartedResolverArgs {
88
+ readonly sessionId: SessionId;
89
+ readonly taskId: TaskId;
90
+ /** `true` for fresh admission; `false` for idempotent existing-session return. */
91
+ readonly isNew: boolean;
92
+ /** Session state at ack time (present when `isNew === false`). */
93
+ readonly state?: SessionState;
94
+ /** Prior task id on terminal re-dispatch (the current `taskId` is the NEW task). */
95
+ readonly previousTaskId?: TaskId;
96
+ /** Prior task's terminal state on terminal re-dispatch. */
97
+ readonly previousState?: SessionState;
98
+ }
99
+ /**
100
+ * Argument shape for the `task.force_resumed` resolver — the ack envelope
101
+ * returned by QAR in response to an outbound `task.forceResume`. Carries
102
+ * the recovered task's id, the post-recovery state (typically
103
+ * `'auto-paused'` after in-flight tool/HITL cancellation; reports the
104
+ * actual state on passthrough), and the inherited derived `session_id`.
105
+ */
106
+ export interface TaskForceResumedResolverArgs {
107
+ readonly sessionId: SessionId;
108
+ readonly taskId: TaskId;
109
+ readonly state: SessionState;
110
+ }
111
+ /**
112
+ * A single task's inbound stream. Routes by parent-message chain: every
113
+ * envelope whose `parent_message_id` is in the chain becomes part of the chain
114
+ * (its `message_id` joins). Terminal envelopes (`task.done`, `error`) close the
115
+ * iterator.
116
+ *
117
+ * On `Connection`-level reconnect, the matching subscription stays alive and
118
+ * the `Connection` stitches the resubscribe envelope's id into `chain` so the
119
+ * server's replayed envelopes route back here transparently.
120
+ */
121
+ export declare class TaskSubscription implements InboundSubscription, AsyncIterable<TaskEvent>, AsyncIterator<TaskEvent> {
122
+ private readonly rootMessageId;
123
+ private readonly onEarlyReturn;
124
+ private readonly onClose;
125
+ /**
126
+ * Optional transport-counter store. When provided, `consider` increments
127
+ * `replay_envelopes_received_total` for every absorbed envelope that
128
+ * descends from a replay anchor, and `replay_anchor_missing_total` for
129
+ * every `error { code: 'replay_anchor_missing' }` envelope that routes
130
+ * here.
131
+ */
132
+ private readonly metrics?;
133
+ private readonly queue;
134
+ private readonly chain;
135
+ /**
136
+ * Lineage-ownership set — message_ids this subscription OWNS, used to
137
+ * attribute an inbound `tool.request` to the turn that produced it (so the
138
+ * SDK's `qar.client.tool.handler` span runs in the right task context).
139
+ *
140
+ * Distinct from {@link chain}, which is the broader ROUTING set: `chain`
141
+ * also accepts envelopes via the `task_id` fallback (a passive same-task
142
+ * subscription — e.g. an auto-paused prior `tasks.start` sub — absorbs
143
+ * another turn's stream that way for observation + replay continuity).
144
+ * `ownedMessages` grows ONLY through real `parent_message_id` lineage: this
145
+ * subscription's own outbound root(s), plus every inbound envelope whose
146
+ * parent it ALREADY owns. It never grows via the `task_id` fallback.
147
+ *
148
+ * Invariant (by construction): every message is owned by EXACTLY ONE
149
+ * subscription. Roots are unique per outbound request; a child is owned by
150
+ * its parent's unique owner. So a `tool.request` — which carries no
151
+ * `task_id` and links only by `parent_message_id` — has a unique owner: the
152
+ * subscription whose `ownedMessages` contains its parent. This is why a
153
+ * passive same-task absorber, which holds the other turn's deltas in `chain`
154
+ * but never in `ownedMessages` (their parent is a root it doesn't own),
155
+ * never wins ownership of that turn's tool calls — at any depth.
156
+ */
157
+ private readonly ownedMessages;
158
+ private taskId;
159
+ /**
160
+ * `message_id` of the most recent inbound envelope that matched this
161
+ * subscription's chain or `task_id`. Anchor for `task.resubscribe` on
162
+ * reconnect — the server replays everything after this point. Stays
163
+ * `undefined` until the first inbound envelope arrives. Connection-scoped
164
+ * envelopes (`flow.pause` / `flow.resume`) don't update it: they're
165
+ * session-scoped, not task-scoped, so they can't anchor a per-task replay
166
+ * window.
167
+ */
168
+ private lastSeen;
169
+ /**
170
+ * Outbound `task.resubscribe` message ids whose direct descendant marks
171
+ * the start of replay accounting for this subscription. Seeded by
172
+ * {@link attachOutboundMessageId} (auto-reconnect) and the constructor's
173
+ * `rootIsReplayAnchor` flag (manual `tasks.resubscribe`). Stays small —
174
+ * one entry per resubscribe envelope this subscription owns, not one
175
+ * entry per replay envelope received.
176
+ */
177
+ private readonly replayAnchors;
178
+ /**
179
+ * Once an envelope absorbed by this subscription has been identified as
180
+ * a replay descendant (its `parent_message_id` was in `replayAnchors`),
181
+ * every subsequently-absorbed envelope is also counted as a replay
182
+ * envelope: QAR's per-session ring buffer replays a contiguous chain
183
+ * after the anchor, so the post-anchor continuation is logically the
184
+ * same wire window as the replay itself.
185
+ *
186
+ * Sticky boolean rather than a growing chain Set — cheaper memory
187
+ * profile for long-running subscriptions that survive many reconnects.
188
+ */
189
+ private replayCountingActive;
190
+ /**
191
+ * @param rootMessageId message_id of the outbound envelope that started the
192
+ * task (the `task.start` or `task.continue`).
193
+ * @param knownTaskId task_id known up front (only for `tasks.continue` /
194
+ * `tasks.cancel` / `tasks.resubscribe` — `tasks.start`
195
+ * doesn't know the id until the first inbound envelope
196
+ * reveals it). Pre-seeding the matcher closes a
197
+ * routing gap where envelopes that carry
198
+ * `payload.task_id` but no chain link to our outbound
199
+ * message would otherwise be missed.
200
+ * @param onEarlyReturn called once if the consumer breaks the iterator
201
+ * before terminal — best-effort `task.cancel`. Pass a
202
+ * no-op for resubscribe-style subscriptions where
203
+ * breaking the loop must NOT cancel the underlying
204
+ * task (the consumer is observing, not driving).
205
+ * @param onClose called once when the subscription is no longer
206
+ * routable (terminal received OR consumer broke).
207
+ */
208
+ /** Span lifecycle for the task this subscription represents. Closed on terminal/fail/early-return. */
209
+ private readonly span;
210
+ /**
211
+ * Resolver for the `task.started` admission ack. Receives both the
212
+ * inherited `session_id` (server-derived UUID) AND the canonical
213
+ * `task_id` from the envelope's payload — the two ids are distinct on
214
+ * the admission-retry path, where a retried `task.start` carries a
215
+ * fresh `message_id` while the server's canonical task_id stays bound
216
+ * to the FIRST winning attempt.
217
+ *
218
+ * Provided by `TaskClient.subscribeAndSend` for `task.start`
219
+ * subscriptions only — `task.continue` / `task.cancel` /
220
+ * `task.resubscribe` already know the session_id + task_id from a
221
+ * prior admission and don't wire a resolver. `null` once the resolver
222
+ * has fired (resolved OR rejected) — prevents a second resolution
223
+ * from a spec-violating duplicate ack.
224
+ */
225
+ private taskStartedResolver;
226
+ /**
227
+ * Resolver for the `task.force_resumed` ack — fires when the SDK's
228
+ * outbound `task.forceResume` envelope's response arrives. Wired by
229
+ * `TaskClient.forceResume`. Mirrors {@link taskStartedResolver} in
230
+ * shape and lifecycle (null after fire; rejected if the subscription
231
+ * closes before the ack lands).
232
+ */
233
+ private taskForceResumedResolver;
234
+ constructor(rootMessageId: MessageId, knownTaskId: TaskId | undefined, onEarlyReturn: (taskId: TaskId | undefined) => void, onClose: (sub: TaskSubscription) => void, span?: SpanLifecycle,
235
+ /**
236
+ * Optional transport-counter store. When provided, `consider` increments
237
+ * `replay_envelopes_received_total` for every absorbed envelope that
238
+ * descends from a replay anchor, and `replay_anchor_missing_total` for
239
+ * every `error { code: 'replay_anchor_missing' }` envelope that routes
240
+ * here.
241
+ */
242
+ metrics?: TransportMetrics | undefined,
243
+ /**
244
+ * `true` when `rootMessageId` is itself a `task.resubscribe` envelope —
245
+ * its descendants count as replay envelopes for
246
+ * `replay_envelopes_received_total`. Set by the manual
247
+ * `client.tasks.resubscribe(...)` seam; the `tasks.start` /
248
+ * `tasks.continue` paths leave it `false` so live envelopes don't
249
+ * masquerade as replay until an auto-replay anchor is stitched in via
250
+ * {@link attachOutboundMessageId}.
251
+ */
252
+ rootIsReplayAnchor?: boolean,
253
+ /**
254
+ * Optional resolver fired with the server-derived `session_id` when
255
+ * the `task.started` admission ack arrives on this subscription's
256
+ * chain. Wired by `task.start` paths so the caller's `TaskStartIterable`
257
+ * can expose the derived id via its `sessionId` Promise.
258
+ *
259
+ * Resolver lifecycle:
260
+ * - Resolved on inbound `task.started` whose `parent_message_id`
261
+ * matches the outbound `task.start.message_id`.
262
+ * - Rejected if the subscription terminates (clean close, transport
263
+ * fail, terminal `task.done` / `error`) before any `task.started`
264
+ * arrives — keeps the consumer's `await stream.sessionId` from
265
+ * hanging forever.
266
+ */
267
+ taskStartedResolver?: {
268
+ readonly resolve: (args: TaskStartedResolverArgs) => void;
269
+ readonly reject: (err: Error) => void;
270
+ },
271
+ /**
272
+ * Optional resolver fired with the recovered task's id +
273
+ * post-recovery state when an inbound `task.force_resumed` ack
274
+ * arrives on this subscription's chain. Wired by
275
+ * `TaskClient.forceResume`. Same lifecycle as
276
+ * {@link taskStartedResolver}: rejected on close/error before
277
+ * the ack lands.
278
+ */
279
+ taskForceResumedResolver?: {
280
+ readonly resolve: (args: TaskForceResumedResolverArgs) => void;
281
+ readonly reject: (err: Error) => void;
282
+ });
283
+ /** The `task_id` once we've seen the first envelope that carries it. */
284
+ get currentTaskId(): TaskId | undefined;
285
+ /**
286
+ * Most-recent inbound envelope's `message_id`, or `undefined` if no inbound
287
+ * matched yet. Public so `Connection.replayActiveTasks` can read it without
288
+ * pinning to a specific subscription class.
289
+ */
290
+ get lastSeenMessageId(): MessageId | undefined;
291
+ /** Whether this subscription has terminated and stopped accepting envelopes. */
292
+ get isTerminated(): boolean;
293
+ /**
294
+ * Stitch a new outbound `message_id` (typically a `task.resubscribe`) into
295
+ * this subscription's chain so the server's replies routed via
296
+ * `parent_message_id` link back here. Idempotent — Set.add no-ops on dups.
297
+ *
298
+ * Called by `Connection` after sending a resubscribe on behalf of an
299
+ * already-live subscription (the auto-replay path on reconnect).
300
+ */
301
+ attachOutboundMessageId(messageId: MessageId): void;
302
+ consider(env: Envelope): boolean;
303
+ /**
304
+ * Reject the pending `task.started` resolver, if any. No-op when the
305
+ * resolver has already fired (resolved earlier on the ack, or rejected
306
+ * by a prior terminal). Idempotent — every terminal path can call
307
+ * this without guarding.
308
+ */
309
+ private rejectTaskStartedIfPending;
310
+ /**
311
+ * Reject the pending `task.force_resumed` resolver, if any. Mirrors
312
+ * {@link rejectTaskStartedIfPending}: idempotent; called from every
313
+ * terminal path so `tasks.forceResume()` Promises don't hang on
314
+ * close / transport failure.
315
+ */
316
+ private rejectTaskForceResumedIfPending;
317
+ /**
318
+ * End the task span for a `task.done` envelope. `completed` and `canceled`
319
+ * are both clean terminal states (the consumer asked for the cancel, or the
320
+ * task ran to completion); `failed` records an error.
321
+ */
322
+ private endSpanForDone;
323
+ considerClient(ev: ClientEvent): void;
324
+ fail(err: Error): void;
325
+ close(): void;
326
+ next(): Promise<IteratorResult<TaskEvent>>;
327
+ return(): Promise<IteratorResult<TaskEvent>>;
328
+ throw(err: unknown): Promise<IteratorResult<TaskEvent>>;
329
+ [Symbol.asyncIterator](): AsyncIterator<TaskEvent>;
330
+ private matches;
331
+ /**
332
+ * Whether `env`'s `parent_message_id` links into this subscription's chain
333
+ * — i.e. the envelope is a direct reply to an outbound message this
334
+ * subscription owns (`task.start` / `task.continue` / `task.resubscribe`,
335
+ * or a prior inbound that already joined the chain).
336
+ *
337
+ * Distinct from the broader {@link matches}, which also accepts an envelope
338
+ * solely because its payload `task_id` equals ours. The admission /
339
+ * recovery acks (`task.started`, `task.force_resumed`) use THIS predicate —
340
+ * not the `task_id` fallback — to decide whether to resolve admission or
341
+ * self-close: those acks carry the canonical `task_id`, which on an
342
+ * idempotent re-admission (a second `task.start` on an already-dispatched
343
+ * session) or a buffer replay equals the id of a DIFFERENT subscription
344
+ * whose task is still streaming. A `task_id`-only match must still absorb
345
+ * the ack (so a cold resubscribe's replayed `task.started` seeds the chain
346
+ * for the chain-only events that follow), but must NOT drive that other
347
+ * subscription's admission/close — see {@link consider}.
348
+ */
349
+ private matchesByChain;
350
+ /**
351
+ * Whether this subscription OWNS `env`'s turn — i.e. its `parent_message_id`
352
+ * is in {@link ownedMessages} (a real lineage link back to our outbound
353
+ * root, never a `task_id`-fallback absorb). Used by
354
+ * {@link Connection.runInOwningTaskContext} to attribute an inbound
355
+ * `tool.request` to the turn that produced it: the owner is unique (each
356
+ * message is owned by exactly one subscription), so this is unambiguous even
357
+ * when multiple same-task subscriptions overlap (e.g. a live auto-paused
358
+ * prior `tasks.start` sub alongside an active `tasks.continue`). A passive
359
+ * absorber holds the other turn's stream in {@link chain} but never in
360
+ * {@link ownedMessages}, so it never wins ownership — at any depth.
361
+ */
362
+ ownsLineage(env: Envelope): boolean;
363
+ /**
364
+ * Public alias for `matches` — exposed so `Connection.dispatchCancelAcked`
365
+ * can route a `task.canceling` envelope to the correct subscription
366
+ * before broadcasting the synthetic `qar.client.cancel_acked` client
367
+ * event. Same chain + `task_id` matcher used for normal envelope
368
+ * routing.
369
+ */
370
+ matchesEnvelope(env: Envelope): boolean;
371
+ /**
372
+ * Run `fn` inside this subscription's task span context. When the
373
+ * subscription has no span (no OTel provider configured, or a call site
374
+ * that didn't supply a span builder), runs `fn` directly — a strict
375
+ * pass-through.
376
+ *
377
+ * Used by {@link Connection.runInOwningTaskContext} to re-attach the
378
+ * originating task's context around an inbound `tool.request` handler
379
+ * dispatch, so the handler's `qar.client.tool.handler` span (and any
380
+ * outbound work it triggers) parents under the task span rather than the
381
+ * bare WS-receive context.
382
+ */
383
+ runInTaskContext<T>(fn: () => T): T;
384
+ }
385
+ /**
386
+ * Raw subscription from `client.receive()` — taps every inbound envelope plus
387
+ * the synthetic `qar.client.*` lifecycle events. The yielded type is
388
+ * `Envelope | ClientEvent`; consumers narrow on `kind` (the QAR `kind`
389
+ * discriminator stays disjoint from `qar.client.*`).
390
+ */
391
+ export declare class RawSubscription implements InboundSubscription, AsyncIterable<Envelope | ClientEvent>, AsyncIterator<Envelope | ClientEvent> {
392
+ private readonly onClose;
393
+ private readonly queue;
394
+ constructor(onClose: (sub: RawSubscription) => void);
395
+ consider(env: Envelope): boolean;
396
+ considerClient(ev: ClientEvent): void;
397
+ fail(err: Error): void;
398
+ close(): void;
399
+ next(): Promise<IteratorResult<Envelope | ClientEvent>>;
400
+ return(): Promise<IteratorResult<Envelope | ClientEvent>>;
401
+ throw(err: unknown): Promise<IteratorResult<Envelope | ClientEvent>>;
402
+ [Symbol.asyncIterator](): AsyncIterator<Envelope | ClientEvent>;
403
+ }
404
+ /**
405
+ * Live connection state. Owns the (replaceable) transport and the set of
406
+ * subscriptions; routes inbound envelopes to subscriptions via `consider`.
407
+ *
408
+ * **No connection-level `sessionId`.** Every `task.start` creates a NEW
409
+ * server-derived session, so an envelope's `session_id` is the TASK's
410
+ * session — not a property of the WebSocket. The SDK tracks
411
+ * `task_id → session_id` and `tool_call_id → session_id` here so that
412
+ * outbound ongoing envelopes can be stamped with the right session at
413
+ * encode time without coupling consumer code to per-task session
414
+ * bookkeeping.
415
+ */
416
+ export declare class Connection {
417
+ private readonly factory;
418
+ private readonly url;
419
+ private readonly headers;
420
+ private readonly traceContext;
421
+ readonly metrics: TransportMetrics;
422
+ private readonly subscriptions;
423
+ /**
424
+ * Map of `task_id → session_id` populated from inbound `task.started`
425
+ * envelopes. Read by {@link sendEnvelope} when encoding `task.continue`
426
+ * / `task.cancel` / `task.resubscribe` so each ongoing envelope
427
+ * carries the same server-derived `session_id` the server bound during
428
+ * admission — preventing multi-task `session_mismatch` without
429
+ * exposing per-task session bookkeeping on the public API.
430
+ *
431
+ * Lifetime: entries are added when `task.started` lands and PRUNED on
432
+ * `task.done` (the wire's terminal ack — task is fully finished). Any
433
+ * later `task.resubscribe` against the same `task_id` would be a
434
+ * cross-process recovery path that has no in-memory session anyway, so
435
+ * pruning doesn't regress that scenario. Cleared on transport close.
436
+ * The auto-reconnect/replay path uses LIVE (non-terminated)
437
+ * subscriptions and adds the session back via the server's replayed
438
+ * `task.started`, so it's unaffected.
439
+ *
440
+ * **Pre-admission invariant.** A live `TaskSubscription` MAY lack an
441
+ * entry in this map: between `tasks.start` writing its outbound
442
+ * `task.start` and the inbound `task.started` ack landing, the
443
+ * subscription is registered in {@link subscriptions} but the
444
+ * `session_id` is not yet pinned here. A WS drop during this window
445
+ * leaves the subscription in an unrecoverable state per the
446
+ * session-identity contract. {@link replayActiveTasks} pre-checks this
447
+ * map before attempting `task.resubscribe` and short-circuits to
448
+ * `sub.fail(QodoColdAddressError)` for un-pinned subs — see that
449
+ * method's JSDoc for the state-machine narrative.
450
+ */
451
+ private readonly taskSessions;
452
+ /**
453
+ * Map of `tool_call_id → session_id` populated from inbound `tool.request`
454
+ * envelopes. Read by {@link sendEnvelope} when encoding `tool.response`,
455
+ * which carries `responses: ToolResponseItem[]` and inherits the parent
456
+ * `tool.request`'s session via the first response item's `tool_call_id`.
457
+ *
458
+ * Lifetime: entries are added when `tool.request` lands and PRUNED on
459
+ * EITHER (a) the outbound `tool.response` hits the wire (single-use
460
+ * — one request, one response), OR (b) the owning task terminates
461
+ * via `task.done` without the consumer ever responding (manual handler
462
+ * returned `undefined` to indicate async-respond-later, then the task
463
+ * timed out / canceled / completed without the response). Without (b)
464
+ * the map would accumulate orphan `tool_call_id` entries on long-lived
465
+ * connections. Cleared on transport close.
466
+ */
467
+ private readonly toolCallSessions;
468
+ /**
469
+ * Reverse index of `session_id → Set<ToolCallId>`. Populated on
470
+ * inbound `tool.request`
471
+ * (one entry per call). Used to sweep {@link toolCallSessions} when
472
+ * the owning task terminates without a `tool.response` ever being
473
+ * sent for some of its outstanding calls — the manual-handler
474
+ * respond-later path explicitly allows this, and without the sweep
475
+ * the per-call map entries would survive forever on long-lived
476
+ * connections.
477
+ *
478
+ * Indexed by `session_id` (not `task_id`) because that's the
479
+ * dimension `tool.request` envelopes carry on the wire — the SDK
480
+ * derives the owning session via the envelope's `session_id` field,
481
+ * not via any task_id field on the payload.
482
+ */
483
+ private readonly outstandingToolCallsBySession;
484
+ /**
485
+ * Reverse index of outbound `task.continue` message_id →
486
+ * `{ taskId, sessionId }` for envelopes
487
+ * that carried a caller-supplied cold-address `sessionId` override.
488
+ * Populated AFTER the wire write (or queued-drain) succeeds; used to
489
+ * identify which `taskSessions` entry to prune when the server rejects
490
+ * the override with `error { code: 'session_mismatch' }`.
491
+ *
492
+ * Without this index, a wrong cold-address override would pollute
493
+ * {@link taskSessions} (because `sendEnvelope`'s post-send write
494
+ * persists the consumer-supplied value as authoritative) and a
495
+ * subsequent no-override call for the same task would silently reuse
496
+ * the already-rejected session instead of raising
497
+ * {@link QodoColdAddressError}.
498
+ *
499
+ * **Generation safety:** the entry stores the sessionId of the
500
+ * override the offending message carried. Pruning is
501
+ * conditional: we delete `taskSessions[taskId]` ONLY when the
502
+ * authoritative entry still matches the rejected sessionId. If a
503
+ * later send for the same task superseded the override with a fresh
504
+ * (valid) sessionId, the rejection for the stale message must NOT
505
+ * blow away the newer authoritative entry. The reverse-map entry for
506
+ * the offending message_id is deleted unconditionally (it's a per-
507
+ * message tombstone; the message is finished one way or the other).
508
+ *
509
+ * Entries are pruned (a) on inbound `error { code: 'session_mismatch' }`
510
+ * for a known offending_message_id (with generation check), and (b)
511
+ * on inbound `task.done` for the matching task_id (terminal sweep).
512
+ * Cleared on transport-terminal cleanup.
513
+ */
514
+ private readonly outboundOverrideRefs;
515
+ private state;
516
+ /** App-level backpressure flag. Flipped by inbound `flow.pause` / `flow.resume`. */
517
+ private paused;
518
+ /**
519
+ * FIFO of pre-encoded JSON frames that arrived while paused. Drained in
520
+ * insertion order on `flow.resume`. Pre-encoding at queue-time keeps the
521
+ * drain path a thin pass-through to the transport.
522
+ *
523
+ * Each entry is tagged with the envelope's `messageId` so the owning
524
+ * `TaskSubscription` can retract its frame on early termination (abort or
525
+ * iterator break) — without that link, a queued `task.continue` would
526
+ * still go to the wire on `flow.resume` after the consumer has already
527
+ * canceled, producing `cancel → continue` reordering on the server.
528
+ */
529
+ private readonly pausedQueue;
530
+ private readonly pausedQueueMax;
531
+ /** Reconnect policy. */
532
+ private readonly reconnectMaxAttempts;
533
+ private readonly reconnectInitialBackoffMs;
534
+ private readonly reconnectBackoffMultiplier;
535
+ /**
536
+ * Pending backoff sleeps. Each entry pairs the timer handle with the
537
+ * Promise's resolve callback so `disconnect()` mid-reconnect can both
538
+ * cancel the timer AND wake the loop up so it observes the new state on
539
+ * the next iteration — without the resolver, clearing the timer would
540
+ * leave the await pending forever.
541
+ */
542
+ private readonly pendingSleeps;
543
+ /** The active transport. Mutable — replaced on every successful reconnect. */
544
+ private transport;
545
+ /** Bound handler instance reused across every transport (initial + reconnects). */
546
+ private readonly handlers;
547
+ private constructor();
548
+ /**
549
+ * Construct + open a fresh connection through the factory. The connection
550
+ * captures the factory + url + headers so it can re-open on transport drops
551
+ * without the caller threading them through again.
552
+ */
553
+ static open(args: {
554
+ factory: WSTransportFactory;
555
+ url: string;
556
+ headers: Readonly<Record<string, string>>;
557
+ maxPausedQueueSize?: number;
558
+ reconnect?: ClientReconnectOptions;
559
+ traceContext: TraceContextProvider;
560
+ metrics: TransportMetrics;
561
+ }): Promise<Connection>;
562
+ /**
563
+ * Encode and send an outbound envelope. Returns the assigned `message_id` so
564
+ * the caller can track the parent_message_id chain.
565
+ *
566
+ * Optionally accepts a pre-allocated `messageId` so subscriptions can be
567
+ * registered against a known root before the envelope hits the wire — avoids
568
+ * a race where an inbound reply could be dispatched before the subscription
569
+ * is in place.
570
+ *
571
+ * If the connection is in `flow.pause` and `out.kind` is throttled
572
+ * (`task.start` / `task.continue`), the encoded frame is enqueued and drained
573
+ * once `flow.resume` arrives. The returned `messageId` is still allocated
574
+ * synchronously so callers can register subscriptions against it before the
575
+ * envelope hits the wire — same invariant as the unpaused path.
576
+ *
577
+ * Throws `QodoBackpressureError` when the queue is at its cap.
578
+ */
579
+ sendEnvelope(out: OutboundPayload, opts?: {
580
+ readonly messageId?: MessageId;
581
+ readonly parentMessageId?: MessageId;
582
+ /**
583
+ * Explicit per-Task `session_id` override. Used by the
584
+ * `ToolRequestDispatcher` to stamp the auto-emitted `tool.response`
585
+ * with the session it captured from the inbound `tool.request` envelope
586
+ * (the source of truth for that response's session). When omitted,
587
+ * {@link sendEnvelope} resolves the `session_id` from
588
+ * {@link taskSessions} or {@link toolCallSessions} based on the
589
+ * envelope's `kind`.
590
+ */
591
+ readonly sessionId?: SessionId;
592
+ }): MessageId;
593
+ /**
594
+ * Resolve the per-Task `session_id` for an outbound ongoing envelope.
595
+ * Caller-supplied `override` wins (the dispatcher path passes the
596
+ * captured inbound `session_id` directly, and the cold-address
597
+ * public-API path passes the consumer-supplied option); otherwise look
598
+ * up by the payload's task_id (`task.continue` / `task.cancel` /
599
+ * `task.resubscribe`) or by the first response item's tool_call_id
600
+ * (`tool.response`).
601
+ *
602
+ * When neither an override NOR an in-memory entry is available, throw
603
+ * {@link QodoColdAddressError} synchronously. Throwing locally:
604
+ *
605
+ * - puts the cold-address remediation right in the error message
606
+ * (consumer should pass `sessionId` from durable storage),
607
+ * - saves a wire round-trip + the misleading `session_mismatch`
608
+ * error message ("envelope session_id differs from connection
609
+ * session" — true but unactionable),
610
+ * - matches the doctrinal correct shape (make it right, not make
611
+ * it work).
612
+ *
613
+ * The primary cross-task session-leak guard is the lookup itself when
614
+ * admission HAS completed.
615
+ */
616
+ private resolveOutboundSessionId;
617
+ /**
618
+ * Retract a queued throttled envelope by its `message_id`. Called by
619
+ * `TaskSubscription` when it terminates early (abort signal, iterator
620
+ * break, transport failure) so the consumer's cancel intent doesn't race
621
+ * with their own queued frame on the next `flow.resume`.
622
+ *
623
+ * No-op if the messageId isn't queued (already drained, never queued, or
624
+ * a different envelope kind that doesn't enter the throttle path).
625
+ * Returns whether an entry was removed — informational only.
626
+ */
627
+ dropQueued(messageId: MessageId): boolean;
628
+ /** Send a raw envelope verbatim — escape hatch. */
629
+ sendRawEnvelope(env: Envelope): void;
630
+ /**
631
+ * Look up the server-derived `session_id` for a known `task_id`.
632
+ * Used by span recorders that want to stamp `qar.session_id`
633
+ * on per-Task spans without coupling caller code to the per-Task lookup
634
+ * map. Returns `undefined` when no `task.started` ack has arrived for
635
+ * this `task_id` yet (the start path's span is opened pre-admission and
636
+ * must tolerate this).
637
+ */
638
+ getSessionForTask(taskId: TaskId): SessionId | undefined;
639
+ /**
640
+ * Look up the `session_id` of the inbound `tool.request` a given
641
+ * `tool_call_id` came from. Used by `ToolClient.respond` to stamp
642
+ * its outbound `tool.response` span with the right session without
643
+ * threading the value through every call site. Returns `undefined` when
644
+ * no matching `tool.request` arrived (test-only path, or a malformed
645
+ * consumer call).
646
+ */
647
+ getSessionForToolCall(toolCallId: ToolCallId): SessionId | undefined;
648
+ /**
649
+ * Run `fn` inside the span context of the live `TaskSubscription` that
650
+ * OWNS `env` by lineage, so an inbound `tool.request` dispatched to the
651
+ * consumer's handler inherits the originating turn's trace context (its
652
+ * `qar.client.task.*` span). Without this, the fanout invokes the handler
653
+ * under the bare WS-receive context and the SDK's `qar.client.tool.handler`
654
+ * span — plus the consumer's outbound MCP/fetch traceparent — are orphaned
655
+ * from the task trace.
656
+ *
657
+ * Ownership is the unique subscription whose {@link TaskSubscription.ownsLineage}
658
+ * holds for `env` — its `parent_message_id` traces (through real
659
+ * `parent_message_id` links) back to that subscription's own outbound root.
660
+ * This is unambiguous even when same-task subscriptions overlap (a live
661
+ * auto-paused `tasks.start` sub alongside an active `tasks.continue`): the
662
+ * passive sub absorbs the active turn's stream into its routing chain via
663
+ * the `task_id` fallback, but never into its ownership lineage, so it never
664
+ * wins — at any tool-call depth (multi-round T1→D2→T2).
665
+ *
666
+ * Terminated subscriptions are skipped (a live task owns an in-flight tool
667
+ * call). Falls through to `fn()` unchanged when no owner is found — a strict
668
+ * no-op for non-OTel consumers, for a `tool.request` whose lineage root was
669
+ * never sent by this process (cold `task.resubscribe` replay), and for an
670
+ * owner with no span.
671
+ */
672
+ runInOwningTaskContext<T>(env: Envelope, fn: () => T): T;
673
+ /** Register a subscription. Caller is responsible for unregistering on close. */
674
+ subscribe(sub: InboundSubscription): void;
675
+ unsubscribe(sub: InboundSubscription): void;
676
+ /**
677
+ * Tear down: close transport, fail all subscriptions cleanly. Idempotent.
678
+ * Called by `QodoClient.disconnect()` and by the `onClose` transport handler
679
+ * for clean closes. Mid-reconnect calls switch state to `disconnecting` so
680
+ * the in-flight loop bails on the next tick.
681
+ */
682
+ close(): void;
683
+ /**
684
+ * Drop any queued envelopes and clear the paused flag. Called on every
685
+ * tear-down path (clean close, transport error, transport close) — leaving
686
+ * frames in the queue past disconnect would either leak memory or surface
687
+ * stale outbound on a future connection that reused this object.
688
+ *
689
+ * Does NOT clear the per-Task / per-Tool-call session-id lookup maps —
690
+ * those must survive the reconnect window so `replayActiveTasks` can
691
+ * stamp the right `session_id` on each `task.resubscribe` envelope it
692
+ * emits. Final cleanup of the session maps lives in
693
+ * {@link clearTerminalState}, invoked from the actual tear-down paths.
694
+ */
695
+ private clearBackpressureState;
696
+ /**
697
+ * Drop the per-Task and per-Tool-call session-id lookup maps. Called
698
+ * from terminal cleanup paths (`close`,
699
+ * `cleanCloseAndCleanup`, `failHardAndCleanup`, `finalizeDisconnect`) so
700
+ * a future `connect()` reusing the same `Connection` object starts with
701
+ * an empty session-id table. Distinct from {@link clearBackpressureState}
702
+ * because the reconnect path MUST keep these populated for replay.
703
+ */
704
+ private clearTerminalState;
705
+ /** Whether the connection accepts outbound sends right now. */
706
+ get isOpen(): boolean;
707
+ /**
708
+ * Whether the connection is mid-reconnect. `isOpen` is false during this
709
+ * window; outbound sends throw. Tests + observability surfaces read this
710
+ * to render a "reconnecting" indicator.
711
+ */
712
+ get isReconnecting(): boolean;
713
+ /**
714
+ * Whether the server has signalled `flow.pause` and we have not yet seen
715
+ * `flow.resume`. While `true`, throttled outbound kinds are queued.
716
+ */
717
+ get isPaused(): boolean;
718
+ /**
719
+ * Snapshot of the paused-queue depth. Useful for tests and observability;
720
+ * not a live counter (no subscription, no event).
721
+ */
722
+ get pausedQueueDepth(): number;
723
+ /** Raw outbound predicate — connected AND transport is in OPEN state. */
724
+ private canSend;
725
+ private dispatch;
726
+ /**
727
+ * Translate an inbound `task.canceling` envelope into a typed
728
+ * `ClientCancelAckedEvent` and route it to the subscription whose chain
729
+ * (or `task_id`) matches. Scoped — not connection-wide — so a consumer
730
+ * running multiple tasks only sees the ack for the task they're
731
+ * iterating.
732
+ *
733
+ * Skips taps (`RawSubscription` already received the envelope through
734
+ * `fanout`); fans into `TaskSubscription` (matching by `task_id` /
735
+ * chain) and observer ports (no-op `considerClient`).
736
+ */
737
+ private dispatchCancelAcked;
738
+ /**
739
+ * Flush the paused queue in FIFO order. Stops if the transport closes
740
+ * mid-drain (a `transport.send` after close would throw and lose the
741
+ * remaining frames silently). Caller is responsible for ensuring `paused`
742
+ * is `false` before invoking — this method does not reset the flag.
743
+ *
744
+ * Drain failure preserves queue state. The earlier shape ("slice +
745
+ * clear + iterate") dropped every
746
+ * REMAINING entry (including their `overrideToSave` metadata) when
747
+ * `transport.send` threw mid-drain. The post-send-success invariant
748
+ * says the override write is conditional on wire-success; an entry
749
+ * that
750
+ * never reaches the wire MUST stay in the queue so the next drain
751
+ * (after the transport recovers and `flow.resume` arrives again,
752
+ * or via the reconnect-loop's eventual retry) can replay it with
753
+ * the same metadata intact.
754
+ *
755
+ * New shape: walk by INDEX without clearing the queue first.
756
+ * - For each entry, send + commit override. If both succeed,
757
+ * mark the index as drained.
758
+ * - If `transport.send` throws OR `canSend()` flips mid-drain,
759
+ * stop immediately, splice off only the successfully drained
760
+ * prefix. Everything from the failing index onward stays in
761
+ * `pausedQueue` for the next drain attempt.
762
+ *
763
+ * The naive `while (length > 0) shift()` form is O(n²) because each
764
+ * `shift()` reindexes the whole array; with a user-configurable cap
765
+ * the blocking time on a large drain shows up in the inbound-message
766
+ * handler. Index-walk + single splice at the end keeps the drain O(n).
767
+ */
768
+ private drainPausedQueue;
769
+ private fanout;
770
+ private broadcastClient;
771
+ /**
772
+ * Wire-level error from the transport. If the user hasn't disconnected and
773
+ * we have something worth replaying, kick off the reconnect loop. Otherwise
774
+ * fail the subscriptions and shut down.
775
+ *
776
+ * Re-entrancy: a custom `WSTransport.close()` may synchronously invoke
777
+ * `handlers.onClose` (the `WSTransport` interface places no async-vs-sync
778
+ * contract on close-event timing — only that one fires). If we called
779
+ * `disposeTransportSafely()` while `state` was still `'connected'`, the
780
+ * synchronous `onClose` would re-enter `transportClosed`, see state still
781
+ * `'connected'`, and start its own reconnect loop. Then this method would
782
+ * return and start ANOTHER one. To prevent this, we transition state OUT
783
+ * of `'connected'` before disposing — any re-entrant `transportClosed` /
784
+ * `transportFailed` then sees the guard and returns early.
785
+ */
786
+ private transportFailed;
787
+ /**
788
+ * Transport closed. Clean codes (1000/1001/1005) end the subs cleanly even
789
+ * if reconnect would otherwise be possible — the server told us to go.
790
+ * Unexpected codes drop into the same reconnect loop as `transportFailed`.
791
+ *
792
+ * Re-entrancy: same guard as `transportFailed` — state transitions before
793
+ * disposal so a synchronous `onClose` from `transport.close()` can't fire
794
+ * a second reconnect loop. Clean closes use a separate guard state
795
+ * (`'disconnecting'` → `'disconnected'`) for the same reason.
796
+ */
797
+ private transportClosed;
798
+ /**
799
+ * Reconnect is worth attempting only when there's at least one in-flight
800
+ * task subscription that can be replayed. A connection with no live tasks
801
+ * and only raw taps gains nothing from a reconnect — the user can call
802
+ * `connect()` fresh next time they need it.
803
+ */
804
+ private shouldAttemptReconnect;
805
+ /**
806
+ * Reconnect loop. Backs off exponentially, retries up to `maxAttempts`. On
807
+ * success: swap the transport, broadcast `qar.client.reconnected`, fire a
808
+ * `task.resubscribe` per active task. On exhaustion: broadcast
809
+ * `qar.client.reconnect_failed`, fail every subscription.
810
+ *
811
+ * Mid-loop user disconnect is honored — we check `state` after every async
812
+ * boundary and bail with a clean close.
813
+ */
814
+ private runReconnectLoop;
815
+ /**
816
+ * For each active task subscription, send a `task.resubscribe` envelope
817
+ * using its `lastSeenMessageId` as the anchor. The new envelope's id is
818
+ * stitched into the subscription's chain so the server's replayed
819
+ * envelopes route back transparently.
820
+ *
821
+ * **Active-subscription state machine.** A `TaskSubscription`
822
+ * registered in `this.subscriptions` can be in one of three states at
823
+ * any point in a connection's lifetime:
824
+ *
825
+ * 1. **pre-admission** — `tasks.start` sent its outbound envelope on
826
+ * the wire and the SDK eagerly registered the subscription so
827
+ * inbound routing can find it. The server-derived `session_id`
828
+ * is NOT yet in {@link taskSessions} because no `task.started`
829
+ * ack has been observed. `currentTaskId` IS set (derived from
830
+ * `task.start.message_id` per the wire contract `task_id ==
831
+ * task.start.message_id`).
832
+ * 2. **admitted** — the `task.started` ack landed; the canonical
833
+ * `task_id` is in `currentTaskId` and the matching `session_id`
834
+ * is pinned in {@link taskSessions}. Resubscribe is fully
835
+ * addressable.
836
+ * 3. **terminated** — `task.done`, server-error, transport-fail,
837
+ * or consumer-driven close has flipped `isTerminated` true.
838
+ * `onClose` has already unsubscribed; subs in this state should
839
+ * not be in the iterating snapshot.
840
+ *
841
+ * `replayActiveTasks` must handle states (1) and (2) explicitly.
842
+ * State (1) is **unrecoverable** per the session-identity contract:
843
+ * without an in-memory `session_id`, the SDK cannot construct a
844
+ * wire-valid `task.resubscribe` for the server's pre-merge
845
+ * bind-and-derive ingress (the resubscribe envelope MUST carry the
846
+ * correct `session_id` field per the QAR wire schema).
847
+ *
848
+ * **Implementation note.** The implementation pre-checks the per-Task
849
+ * session map BEFORE attempting the wire send. A state-(1) sub is
850
+ * failed with a freshly-constructed `QodoColdAddressError` whose
851
+ * stack starts cleanly inside `replayActiveTasks` — no wire
852
+ * round-trip is attempted; the failure is local, typed, and
853
+ * origin-traceable. An earlier implementation called
854
+ * {@link sendEnvelope} first and relied on the synchronous throw
855
+ * from {@link resolveOutboundSessionId} to route the failure into
856
+ * `sub.fail(err)` — functionally correct but the thrown error
857
+ * carried a misleading stack (the wire-send frames). The current
858
+ * pre-check approach surfaces a typed local failure instead.
859
+ * The consumer-facing API surface is unchanged: state-(1) subs still
860
+ * surface `QodoColdAddressError` on their iterator. Lost-ack
861
+ * idempotent retry (re-issuing the original `task.start` on the new
862
+ * transport with the same idempotency-key) lives at the layer
863
+ * above; the raw `Connection` ships the typed failure.
864
+ *
865
+ * Every `TaskSubscription` carries a known `task_id` from construction:
866
+ * `tasks.continue` / `tasks.cancel` / `tasks.resubscribe` receive it from
867
+ * the caller, and `tasks.start` derives it from the outbound
868
+ * `task.start.message_id`. The `currentTaskId === undefined` case is
869
+ * therefore unreachable here — we keep an invariant assertion rather
870
+ * than the prior "in-flight task is unrecoverable" `sub.fail` path.
871
+ */
872
+ private replayActiveTasks;
873
+ private cleanCloseAndCleanup;
874
+ private failHardAndCleanup;
875
+ /**
876
+ * Walk the user-initiated disconnect path from inside the reconnect loop.
877
+ * The subs are still registered (we deferred their close); end them
878
+ * cleanly so `for await` consumers see `done: true` rather than an error.
879
+ */
880
+ private finalizeDisconnect;
881
+ private disposeTransportSafely;
882
+ private clearPendingTimers;
883
+ /**
884
+ * Sleep for `ms` milliseconds, cancellable by `clearPendingTimers`. Returns
885
+ * even if the timer is cleared early — the caller checks `state` after the
886
+ * await to decide whether to proceed. Cancelling resolves the Promise
887
+ * rather than rejecting it: cancellation is a flow-control signal, not an
888
+ * error, and the reconnect loop's post-await state check handles it.
889
+ */
890
+ private sleepCancellable;
891
+ }
892
+ export type { WSTransportFactoryArgs };
893
+ //# sourceMappingURL=connection.d.ts.map