@bradygaster/squad-sdk 0.7.0 → 0.8.2-1.4

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 (443) hide show
  1. package/README.md +3 -3
  2. package/dist/adapter/client.d.ts +246 -0
  3. package/dist/adapter/client.d.ts.map +1 -0
  4. package/dist/adapter/client.js +699 -0
  5. package/dist/adapter/client.js.map +1 -0
  6. package/dist/adapter/errors.d.ts +260 -0
  7. package/dist/adapter/errors.d.ts.map +1 -0
  8. package/dist/adapter/errors.js +362 -0
  9. package/dist/adapter/errors.js.map +1 -0
  10. package/dist/adapter/types.d.ts +817 -0
  11. package/dist/adapter/types.d.ts.map +1 -0
  12. package/dist/adapter/types.js +11 -0
  13. package/dist/adapter/types.js.map +1 -0
  14. package/dist/agents/charter-compiler.d.ts +106 -0
  15. package/dist/agents/charter-compiler.d.ts.map +1 -0
  16. package/dist/agents/charter-compiler.js +165 -0
  17. package/dist/agents/charter-compiler.js.map +1 -0
  18. package/dist/agents/history-shadow.d.ts +80 -0
  19. package/dist/agents/history-shadow.d.ts.map +1 -0
  20. package/dist/agents/history-shadow.js +239 -0
  21. package/dist/agents/history-shadow.js.map +1 -0
  22. package/dist/agents/index.d.ts +71 -0
  23. package/dist/agents/index.d.ts.map +1 -0
  24. package/dist/agents/index.js +183 -0
  25. package/dist/agents/index.js.map +1 -0
  26. package/dist/agents/lifecycle.d.ts +138 -0
  27. package/dist/agents/lifecycle.d.ts.map +1 -0
  28. package/dist/agents/lifecycle.js +284 -0
  29. package/dist/agents/lifecycle.js.map +1 -0
  30. package/dist/agents/model-selector.d.ts +80 -0
  31. package/dist/agents/model-selector.d.ts.map +1 -0
  32. package/dist/agents/model-selector.js +171 -0
  33. package/dist/agents/model-selector.js.map +1 -0
  34. package/dist/agents/onboarding.d.ts +65 -0
  35. package/dist/agents/onboarding.d.ts.map +1 -0
  36. package/dist/agents/onboarding.js +373 -0
  37. package/dist/agents/onboarding.js.map +1 -0
  38. package/dist/build/bundle.d.ts +32 -0
  39. package/dist/build/bundle.d.ts.map +1 -0
  40. package/dist/build/bundle.js +97 -0
  41. package/dist/build/bundle.js.map +1 -0
  42. package/dist/build/ci-pipeline.d.ts +51 -0
  43. package/dist/build/ci-pipeline.d.ts.map +1 -0
  44. package/dist/build/ci-pipeline.js +180 -0
  45. package/dist/build/ci-pipeline.js.map +1 -0
  46. package/dist/build/github-dist.d.ts +37 -0
  47. package/dist/build/github-dist.d.ts.map +1 -0
  48. package/dist/build/github-dist.js +117 -0
  49. package/dist/build/github-dist.js.map +1 -0
  50. package/dist/build/index.d.ts +11 -0
  51. package/dist/build/index.d.ts.map +1 -0
  52. package/dist/build/index.js +11 -0
  53. package/dist/build/index.js.map +1 -0
  54. package/dist/build/install-migration.d.ts +28 -0
  55. package/dist/build/install-migration.d.ts.map +1 -0
  56. package/dist/build/install-migration.js +103 -0
  57. package/dist/build/install-migration.js.map +1 -0
  58. package/dist/build/npm-package.d.ts +54 -0
  59. package/dist/build/npm-package.d.ts.map +1 -0
  60. package/dist/build/npm-package.js +128 -0
  61. package/dist/build/npm-package.js.map +1 -0
  62. package/dist/build/release.d.ts +108 -0
  63. package/dist/build/release.d.ts.map +1 -0
  64. package/dist/build/release.js +295 -0
  65. package/dist/build/release.js.map +1 -0
  66. package/dist/build/versioning.d.ts +38 -0
  67. package/dist/build/versioning.d.ts.map +1 -0
  68. package/dist/build/versioning.js +113 -0
  69. package/dist/build/versioning.js.map +1 -0
  70. package/dist/builders/index.d.ts +156 -0
  71. package/dist/builders/index.d.ts.map +1 -0
  72. package/dist/builders/index.js +404 -0
  73. package/dist/builders/index.js.map +1 -0
  74. package/dist/builders/types.d.ts +187 -0
  75. package/dist/builders/types.d.ts.map +1 -0
  76. package/dist/builders/types.js +12 -0
  77. package/dist/builders/types.js.map +1 -0
  78. package/dist/casting/casting-engine.d.ts +60 -0
  79. package/dist/casting/casting-engine.d.ts.map +1 -0
  80. package/dist/casting/casting-engine.js +223 -0
  81. package/dist/casting/casting-engine.js.map +1 -0
  82. package/dist/casting/casting-history.d.ts +54 -0
  83. package/dist/casting/casting-history.d.ts.map +1 -0
  84. package/dist/casting/casting-history.js +63 -0
  85. package/dist/casting/casting-history.js.map +1 -0
  86. package/dist/casting/index.d.ts +46 -0
  87. package/dist/casting/index.d.ts.map +1 -0
  88. package/dist/casting/index.js +45 -0
  89. package/dist/casting/index.js.map +1 -0
  90. package/dist/client/event-bus.d.ts +29 -0
  91. package/dist/client/event-bus.d.ts.map +1 -0
  92. package/dist/client/event-bus.js +52 -0
  93. package/dist/client/event-bus.js.map +1 -0
  94. package/dist/client/index.d.ts +103 -0
  95. package/dist/client/index.d.ts.map +1 -0
  96. package/dist/client/index.js +182 -0
  97. package/dist/client/index.js.map +1 -0
  98. package/dist/client/session-pool.d.ts +66 -0
  99. package/dist/client/session-pool.d.ts.map +1 -0
  100. package/dist/client/session-pool.js +145 -0
  101. package/dist/client/session-pool.js.map +1 -0
  102. package/dist/config/agent-doc.d.ts +43 -0
  103. package/dist/config/agent-doc.d.ts.map +1 -0
  104. package/dist/config/agent-doc.js +158 -0
  105. package/dist/config/agent-doc.js.map +1 -0
  106. package/dist/config/agent-source.d.ts +95 -0
  107. package/dist/config/agent-source.d.ts.map +1 -0
  108. package/dist/config/agent-source.js +274 -0
  109. package/dist/config/agent-source.js.map +1 -0
  110. package/dist/config/doc-sync.d.ts +66 -0
  111. package/dist/config/doc-sync.d.ts.map +1 -0
  112. package/dist/config/doc-sync.js +270 -0
  113. package/dist/config/doc-sync.js.map +1 -0
  114. package/dist/config/feature-audit.d.ts +49 -0
  115. package/dist/config/feature-audit.d.ts.map +1 -0
  116. package/dist/config/feature-audit.js +148 -0
  117. package/dist/config/feature-audit.js.map +1 -0
  118. package/dist/config/index.d.ts +15 -0
  119. package/dist/config/index.d.ts.map +1 -0
  120. package/dist/config/index.js +15 -0
  121. package/dist/config/index.js.map +1 -0
  122. package/dist/config/init.d.ts +86 -0
  123. package/dist/config/init.d.ts.map +1 -0
  124. package/dist/config/init.js +807 -0
  125. package/dist/config/init.js.map +1 -0
  126. package/dist/config/legacy-fallback.d.ts +83 -0
  127. package/dist/config/legacy-fallback.d.ts.map +1 -0
  128. package/dist/config/legacy-fallback.js +212 -0
  129. package/dist/config/legacy-fallback.js.map +1 -0
  130. package/dist/config/markdown-migration.d.ts +157 -0
  131. package/dist/config/markdown-migration.d.ts.map +1 -0
  132. package/dist/config/markdown-migration.js +434 -0
  133. package/dist/config/markdown-migration.js.map +1 -0
  134. package/dist/config/migration.d.ts +123 -0
  135. package/dist/config/migration.d.ts.map +1 -0
  136. package/dist/config/migration.js +273 -0
  137. package/dist/config/migration.js.map +1 -0
  138. package/dist/config/migrations/index.d.ts +36 -0
  139. package/dist/config/migrations/index.d.ts.map +1 -0
  140. package/dist/config/migrations/index.js +216 -0
  141. package/dist/config/migrations/index.js.map +1 -0
  142. package/dist/config/models.d.ts +134 -0
  143. package/dist/config/models.d.ts.map +1 -0
  144. package/dist/config/models.js +354 -0
  145. package/dist/config/models.js.map +1 -0
  146. package/dist/config/routing.d.ts +118 -0
  147. package/dist/config/routing.d.ts.map +1 -0
  148. package/dist/config/routing.js +247 -0
  149. package/dist/config/routing.js.map +1 -0
  150. package/dist/config/schema.d.ts +72 -0
  151. package/dist/config/schema.d.ts.map +1 -0
  152. package/dist/config/schema.js +63 -0
  153. package/dist/config/schema.js.map +1 -0
  154. package/dist/coordinator/coordinator.d.ts +82 -0
  155. package/dist/coordinator/coordinator.d.ts.map +1 -0
  156. package/dist/coordinator/coordinator.js +192 -0
  157. package/dist/coordinator/coordinator.js.map +1 -0
  158. package/dist/coordinator/direct-response.d.ts +83 -0
  159. package/dist/coordinator/direct-response.d.ts.map +1 -0
  160. package/dist/coordinator/direct-response.js +187 -0
  161. package/dist/coordinator/direct-response.js.map +1 -0
  162. package/dist/coordinator/fan-out.d.ts +83 -0
  163. package/dist/coordinator/fan-out.d.ts.map +1 -0
  164. package/dist/coordinator/fan-out.js +161 -0
  165. package/dist/coordinator/fan-out.js.map +1 -0
  166. package/dist/coordinator/index.d.ts +62 -0
  167. package/dist/coordinator/index.d.ts.map +1 -0
  168. package/dist/coordinator/index.js +177 -0
  169. package/dist/coordinator/index.js.map +1 -0
  170. package/dist/coordinator/response-tiers.d.ts +49 -0
  171. package/dist/coordinator/response-tiers.d.ts.map +1 -0
  172. package/dist/coordinator/response-tiers.js +149 -0
  173. package/dist/coordinator/response-tiers.js.map +1 -0
  174. package/dist/hooks/index.d.ts +103 -0
  175. package/dist/hooks/index.d.ts.map +1 -0
  176. package/dist/hooks/index.js +279 -0
  177. package/dist/hooks/index.js.map +1 -0
  178. package/dist/index.d.ts +37 -1
  179. package/dist/index.d.ts.map +1 -1
  180. package/dist/index.js +37 -3
  181. package/dist/index.js.map +1 -1
  182. package/dist/marketplace/backend.d.ts +35 -0
  183. package/dist/marketplace/backend.d.ts.map +1 -0
  184. package/dist/marketplace/backend.js +99 -0
  185. package/dist/marketplace/backend.js.map +1 -0
  186. package/dist/marketplace/browser.d.ts +33 -0
  187. package/dist/marketplace/browser.d.ts.map +1 -0
  188. package/dist/marketplace/browser.js +97 -0
  189. package/dist/marketplace/browser.js.map +1 -0
  190. package/dist/marketplace/extension-adapter.d.ts +51 -0
  191. package/dist/marketplace/extension-adapter.d.ts.map +1 -0
  192. package/dist/marketplace/extension-adapter.js +81 -0
  193. package/dist/marketplace/extension-adapter.js.map +1 -0
  194. package/dist/marketplace/index.d.ts +51 -0
  195. package/dist/marketplace/index.d.ts.map +1 -0
  196. package/dist/marketplace/index.js +108 -0
  197. package/dist/marketplace/index.js.map +1 -0
  198. package/dist/marketplace/packaging.d.ts +25 -0
  199. package/dist/marketplace/packaging.d.ts.map +1 -0
  200. package/dist/marketplace/packaging.js +117 -0
  201. package/dist/marketplace/packaging.js.map +1 -0
  202. package/dist/marketplace/schema.d.ts +50 -0
  203. package/dist/marketplace/schema.d.ts.map +1 -0
  204. package/dist/marketplace/schema.js +120 -0
  205. package/dist/marketplace/schema.js.map +1 -0
  206. package/dist/marketplace/security.d.ts +26 -0
  207. package/dist/marketplace/security.d.ts.map +1 -0
  208. package/dist/marketplace/security.js +199 -0
  209. package/dist/marketplace/security.js.map +1 -0
  210. package/dist/multi-squad.d.ts +89 -0
  211. package/dist/multi-squad.d.ts.map +1 -0
  212. package/dist/multi-squad.js +233 -0
  213. package/dist/multi-squad.js.map +1 -0
  214. package/dist/parsers.d.ts +15 -0
  215. package/dist/parsers.d.ts.map +1 -0
  216. package/dist/parsers.js +15 -0
  217. package/dist/parsers.js.map +1 -0
  218. package/dist/ralph/index.d.ts +58 -0
  219. package/dist/ralph/index.d.ts.map +1 -0
  220. package/dist/ralph/index.js +128 -0
  221. package/dist/ralph/index.js.map +1 -0
  222. package/dist/ralph/triage.d.ts +48 -0
  223. package/dist/ralph/triage.d.ts.map +1 -0
  224. package/dist/ralph/triage.js +310 -0
  225. package/dist/ralph/triage.js.map +1 -0
  226. package/dist/remote/bridge.d.ts +79 -0
  227. package/dist/remote/bridge.d.ts.map +1 -0
  228. package/dist/remote/bridge.js +583 -0
  229. package/dist/remote/bridge.js.map +1 -0
  230. package/dist/remote/index.d.ts +7 -0
  231. package/dist/remote/index.d.ts.map +1 -0
  232. package/dist/remote/index.js +6 -0
  233. package/dist/remote/index.js.map +1 -0
  234. package/dist/remote/protocol.d.ts +130 -0
  235. package/dist/remote/protocol.d.ts.map +1 -0
  236. package/dist/remote/protocol.js +25 -0
  237. package/dist/remote/protocol.js.map +1 -0
  238. package/dist/remote/types.d.ts +34 -0
  239. package/dist/remote/types.d.ts.map +1 -0
  240. package/dist/remote/types.js +5 -0
  241. package/dist/remote/types.js.map +1 -0
  242. package/dist/resolution.d.ts +119 -0
  243. package/dist/resolution.d.ts.map +1 -0
  244. package/dist/resolution.js +259 -0
  245. package/dist/resolution.js.map +1 -0
  246. package/dist/runtime/benchmarks.d.ts +121 -0
  247. package/dist/runtime/benchmarks.d.ts.map +1 -0
  248. package/dist/runtime/benchmarks.js +251 -0
  249. package/dist/runtime/benchmarks.js.map +1 -0
  250. package/dist/runtime/config.d.ts +314 -0
  251. package/dist/runtime/config.d.ts.map +1 -0
  252. package/dist/runtime/config.js +467 -0
  253. package/dist/runtime/config.js.map +1 -0
  254. package/dist/runtime/constants.d.ts +37 -0
  255. package/dist/runtime/constants.d.ts.map +1 -0
  256. package/dist/runtime/constants.js +60 -0
  257. package/dist/runtime/constants.js.map +1 -0
  258. package/dist/runtime/cost-tracker.d.ts +73 -0
  259. package/dist/runtime/cost-tracker.d.ts.map +1 -0
  260. package/dist/runtime/cost-tracker.js +157 -0
  261. package/dist/runtime/cost-tracker.js.map +1 -0
  262. package/dist/runtime/event-bus-ws-bridge.d.ts +35 -0
  263. package/dist/runtime/event-bus-ws-bridge.d.ts.map +1 -0
  264. package/dist/runtime/event-bus-ws-bridge.js +55 -0
  265. package/dist/runtime/event-bus-ws-bridge.js.map +1 -0
  266. package/dist/runtime/event-bus.d.ts +190 -0
  267. package/dist/runtime/event-bus.d.ts.map +1 -0
  268. package/dist/runtime/event-bus.js +218 -0
  269. package/dist/runtime/event-bus.js.map +1 -0
  270. package/dist/runtime/event-payloads.d.ts +108 -0
  271. package/dist/runtime/event-payloads.d.ts.map +1 -0
  272. package/dist/runtime/event-payloads.js +28 -0
  273. package/dist/runtime/event-payloads.js.map +1 -0
  274. package/dist/runtime/health.d.ts +66 -0
  275. package/dist/runtime/health.d.ts.map +1 -0
  276. package/dist/runtime/health.js +112 -0
  277. package/dist/runtime/health.js.map +1 -0
  278. package/dist/runtime/i18n.d.ts +54 -0
  279. package/dist/runtime/i18n.d.ts.map +1 -0
  280. package/dist/runtime/i18n.js +126 -0
  281. package/dist/runtime/i18n.js.map +1 -0
  282. package/dist/runtime/offline.d.ts +64 -0
  283. package/dist/runtime/offline.d.ts.map +1 -0
  284. package/dist/runtime/offline.js +108 -0
  285. package/dist/runtime/offline.js.map +1 -0
  286. package/dist/runtime/otel-api.d.ts +38 -0
  287. package/dist/runtime/otel-api.d.ts.map +1 -0
  288. package/dist/runtime/otel-api.js +94 -0
  289. package/dist/runtime/otel-api.js.map +1 -0
  290. package/dist/runtime/otel-bridge.d.ts +52 -0
  291. package/dist/runtime/otel-bridge.d.ts.map +1 -0
  292. package/dist/runtime/otel-bridge.js +132 -0
  293. package/dist/runtime/otel-bridge.js.map +1 -0
  294. package/dist/runtime/otel-init.d.ts +84 -0
  295. package/dist/runtime/otel-init.d.ts.map +1 -0
  296. package/dist/runtime/otel-init.js +86 -0
  297. package/dist/runtime/otel-init.js.map +1 -0
  298. package/dist/runtime/otel-metrics.d.ts +42 -0
  299. package/dist/runtime/otel-metrics.d.ts.map +1 -0
  300. package/dist/runtime/otel-metrics.js +196 -0
  301. package/dist/runtime/otel-metrics.js.map +1 -0
  302. package/dist/runtime/otel.d.ts +55 -0
  303. package/dist/runtime/otel.d.ts.map +1 -0
  304. package/dist/runtime/otel.js +165 -0
  305. package/dist/runtime/otel.js.map +1 -0
  306. package/dist/runtime/squad-observer.d.ts +75 -0
  307. package/dist/runtime/squad-observer.d.ts.map +1 -0
  308. package/dist/runtime/squad-observer.js +190 -0
  309. package/dist/runtime/squad-observer.js.map +1 -0
  310. package/dist/runtime/streaming.d.ts +106 -0
  311. package/dist/runtime/streaming.d.ts.map +1 -0
  312. package/dist/runtime/streaming.js +192 -0
  313. package/dist/runtime/streaming.js.map +1 -0
  314. package/dist/runtime/telemetry.d.ts +82 -0
  315. package/dist/runtime/telemetry.d.ts.map +1 -0
  316. package/dist/runtime/telemetry.js +120 -0
  317. package/dist/runtime/telemetry.js.map +1 -0
  318. package/dist/sharing/agent-repo.d.ts +33 -0
  319. package/dist/sharing/agent-repo.d.ts.map +1 -0
  320. package/dist/sharing/agent-repo.js +79 -0
  321. package/dist/sharing/agent-repo.js.map +1 -0
  322. package/dist/sharing/cache.d.ts +36 -0
  323. package/dist/sharing/cache.d.ts.map +1 -0
  324. package/dist/sharing/cache.js +85 -0
  325. package/dist/sharing/cache.js.map +1 -0
  326. package/dist/sharing/conflicts.d.ts +32 -0
  327. package/dist/sharing/conflicts.d.ts.map +1 -0
  328. package/dist/sharing/conflicts.js +123 -0
  329. package/dist/sharing/conflicts.js.map +1 -0
  330. package/dist/sharing/consult.d.ts +226 -0
  331. package/dist/sharing/consult.d.ts.map +1 -0
  332. package/dist/sharing/consult.js +818 -0
  333. package/dist/sharing/consult.js.map +1 -0
  334. package/dist/sharing/export.d.ts +50 -0
  335. package/dist/sharing/export.d.ts.map +1 -0
  336. package/dist/sharing/export.js +156 -0
  337. package/dist/sharing/export.js.map +1 -0
  338. package/dist/sharing/history-split.d.ts +34 -0
  339. package/dist/sharing/history-split.d.ts.map +1 -0
  340. package/dist/sharing/history-split.js +101 -0
  341. package/dist/sharing/history-split.js.map +1 -0
  342. package/dist/sharing/import.d.ts +37 -0
  343. package/dist/sharing/import.d.ts.map +1 -0
  344. package/dist/sharing/import.js +138 -0
  345. package/dist/sharing/import.js.map +1 -0
  346. package/dist/sharing/index.d.ts +12 -0
  347. package/dist/sharing/index.d.ts.map +1 -0
  348. package/dist/sharing/index.js +12 -0
  349. package/dist/sharing/index.js.map +1 -0
  350. package/dist/sharing/versioning.d.ts +32 -0
  351. package/dist/sharing/versioning.d.ts.map +1 -0
  352. package/dist/sharing/versioning.js +64 -0
  353. package/dist/sharing/versioning.js.map +1 -0
  354. package/dist/skills/index.d.ts +49 -0
  355. package/dist/skills/index.d.ts.map +1 -0
  356. package/dist/skills/index.js +85 -0
  357. package/dist/skills/index.js.map +1 -0
  358. package/dist/skills/skill-loader.d.ts +56 -0
  359. package/dist/skills/skill-loader.d.ts.map +1 -0
  360. package/dist/skills/skill-loader.js +106 -0
  361. package/dist/skills/skill-loader.js.map +1 -0
  362. package/dist/skills/skill-source.d.ts +63 -0
  363. package/dist/skills/skill-source.d.ts.map +1 -0
  364. package/dist/skills/skill-source.js +199 -0
  365. package/dist/skills/skill-source.js.map +1 -0
  366. package/dist/streams/filter.d.ts +33 -0
  367. package/dist/streams/filter.d.ts.map +1 -0
  368. package/dist/streams/filter.js +29 -0
  369. package/dist/streams/filter.js.map +1 -0
  370. package/dist/streams/index.d.ts +9 -0
  371. package/dist/streams/index.d.ts.map +1 -0
  372. package/dist/streams/index.js +9 -0
  373. package/dist/streams/index.js.map +1 -0
  374. package/dist/streams/resolver.d.ts +40 -0
  375. package/dist/streams/resolver.d.ts.map +1 -0
  376. package/dist/streams/resolver.js +162 -0
  377. package/dist/streams/resolver.js.map +1 -0
  378. package/dist/streams/types.d.ts +44 -0
  379. package/dist/streams/types.d.ts.map +1 -0
  380. package/dist/streams/types.js +10 -0
  381. package/dist/streams/types.js.map +1 -0
  382. package/dist/tools/index.d.ts +95 -0
  383. package/dist/tools/index.d.ts.map +1 -0
  384. package/dist/tools/index.js +475 -0
  385. package/dist/tools/index.js.map +1 -0
  386. package/dist/types.d.ts +66 -0
  387. package/dist/types.d.ts.map +1 -0
  388. package/dist/types.js +8 -0
  389. package/dist/types.js.map +1 -0
  390. package/dist/upstream/index.d.ts +8 -0
  391. package/dist/upstream/index.d.ts.map +1 -0
  392. package/dist/upstream/index.js +7 -0
  393. package/dist/upstream/index.js.map +1 -0
  394. package/dist/upstream/resolver.d.ts +37 -0
  395. package/dist/upstream/resolver.d.ts.map +1 -0
  396. package/dist/upstream/resolver.js +234 -0
  397. package/dist/upstream/resolver.js.map +1 -0
  398. package/dist/upstream/types.d.ts +55 -0
  399. package/dist/upstream/types.d.ts.map +1 -0
  400. package/dist/upstream/types.js +11 -0
  401. package/dist/upstream/types.js.map +1 -0
  402. package/dist/utils/normalize-eol.d.ts +6 -0
  403. package/dist/utils/normalize-eol.d.ts.map +1 -0
  404. package/dist/utils/normalize-eol.js +8 -0
  405. package/dist/utils/normalize-eol.js.map +1 -0
  406. package/dist/utils/safe-timestamp.d.ts +6 -0
  407. package/dist/utils/safe-timestamp.d.ts.map +1 -0
  408. package/dist/utils/safe-timestamp.js +8 -0
  409. package/dist/utils/safe-timestamp.js.map +1 -0
  410. package/package.json +151 -6
  411. package/templates/casting-history.json +4 -0
  412. package/templates/casting-policy.json +35 -0
  413. package/templates/casting-registry.json +3 -0
  414. package/templates/ceremonies.md +41 -0
  415. package/templates/charter.md +53 -0
  416. package/templates/constraint-tracking.md +38 -0
  417. package/templates/copilot-instructions.md +46 -0
  418. package/templates/history.md +10 -0
  419. package/templates/identity/now.md +9 -0
  420. package/templates/identity/wisdom.md +15 -0
  421. package/templates/mcp-config.md +98 -0
  422. package/templates/multi-agent-format.md +28 -0
  423. package/templates/orchestration-log.md +27 -0
  424. package/templates/plugin-marketplace.md +49 -0
  425. package/templates/raw-agent-output.md +37 -0
  426. package/templates/roster.md +60 -0
  427. package/templates/routing.md +54 -0
  428. package/templates/run-output.md +50 -0
  429. package/templates/scribe-charter.md +119 -0
  430. package/templates/skill.md +24 -0
  431. package/templates/skills/project-conventions/SKILL.md +56 -0
  432. package/templates/squad.agent.md +1146 -0
  433. package/templates/workflows/squad-ci.yml +24 -0
  434. package/templates/workflows/squad-docs.yml +50 -0
  435. package/templates/workflows/squad-heartbeat.yml +316 -0
  436. package/templates/workflows/squad-insider-release.yml +61 -0
  437. package/templates/workflows/squad-issue-assign.yml +161 -0
  438. package/templates/workflows/squad-label-enforce.yml +181 -0
  439. package/templates/workflows/squad-preview.yml +55 -0
  440. package/templates/workflows/squad-promote.yml +120 -0
  441. package/templates/workflows/squad-release.yml +77 -0
  442. package/templates/workflows/squad-triage.yml +260 -0
  443. package/templates/workflows/sync-squad-labels.yml +169 -0
@@ -0,0 +1,699 @@
1
+ /**
2
+ * Squad SDK Client Adapter
3
+ *
4
+ * Wraps CopilotClient to provide connection lifecycle management, error recovery,
5
+ * automatic reconnection, and protocol version validation.
6
+ *
7
+ * @module adapter/client
8
+ */
9
+ import { CopilotClient } from "@github/copilot-sdk";
10
+ import { trace, SpanStatusCode } from '../runtime/otel-api.js';
11
+ import { recordSessionCreated, recordSessionClosed, recordSessionError } from '../runtime/otel-metrics.js';
12
+ const tracer = trace.getTracer('squad-sdk');
13
+ /**
14
+ * Adapts @github/copilot-sdk CopilotSession to our SquadSession interface.
15
+ * Maps sendMessage() → send(), off() via unsubscribe tracking, close() → destroy().
16
+ *
17
+ * Bug reported by @spboyer (Shayne Boyer) — Codespace environment exposed
18
+ * the unsafe `as unknown as` cast that skipped runtime method mapping.
19
+ */
20
+ class CopilotSessionAdapter {
21
+ /**
22
+ * Maps Squad short event names → @github/copilot-sdk dotted event names.
23
+ * SDK uses dotted-namespace prefixes (e.g., `assistant.message_delta`),
24
+ * while Squad uses short names (e.g., `message_delta`).
25
+ * Names already in dotted form pass through via the fallback.
26
+ */
27
+ static EVENT_MAP = {
28
+ 'message_delta': 'assistant.message_delta',
29
+ 'message': 'assistant.message',
30
+ 'usage': 'assistant.usage',
31
+ 'reasoning_delta': 'assistant.reasoning_delta',
32
+ 'reasoning': 'assistant.reasoning',
33
+ 'turn_start': 'assistant.turn_start',
34
+ 'turn_end': 'assistant.turn_end',
35
+ 'intent': 'assistant.intent',
36
+ 'idle': 'session.idle',
37
+ 'error': 'session.error',
38
+ };
39
+ /** Reverse map: SDK dotted names → Squad short names. */
40
+ static REVERSE_EVENT_MAP = Object.fromEntries(Object.entries(CopilotSessionAdapter.EVENT_MAP).map(([k, v]) => [v, k]));
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
+ inner;
43
+ unsubscribers = new Map();
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ constructor(copilotSession) {
46
+ this.inner = copilotSession;
47
+ }
48
+ get sessionId() {
49
+ return this.inner.sessionId ?? 'unknown';
50
+ }
51
+ async sendMessage(options) {
52
+ await this.inner.send(options);
53
+ }
54
+ async sendAndWait(options, timeout) {
55
+ return await this.inner.sendAndWait(options, timeout);
56
+ }
57
+ async abort() {
58
+ await this.inner.abort();
59
+ }
60
+ async getMessages() {
61
+ return await this.inner.getMessages();
62
+ }
63
+ /**
64
+ * Normalizes an SDK event into a SquadSessionEvent.
65
+ * Maps the dotted type back to the Squad short name and
66
+ * flattens `event.data` onto the top-level object so callers
67
+ * can access fields directly (e.g., `event.inputTokens`).
68
+ */
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ static normalizeEvent(sdkEvent) {
71
+ const squadType = CopilotSessionAdapter.REVERSE_EVENT_MAP[sdkEvent.type] ?? sdkEvent.type;
72
+ return {
73
+ type: squadType,
74
+ ...(sdkEvent.data ?? {}),
75
+ };
76
+ }
77
+ on(eventType, handler) {
78
+ const sdkType = CopilotSessionAdapter.EVENT_MAP[eventType] ?? eventType;
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ const wrappedHandler = (sdkEvent) => {
81
+ handler(CopilotSessionAdapter.normalizeEvent(sdkEvent));
82
+ };
83
+ const unsubscribe = this.inner.on(sdkType, wrappedHandler);
84
+ if (!this.unsubscribers.has(handler)) {
85
+ this.unsubscribers.set(handler, new Map());
86
+ }
87
+ this.unsubscribers.get(handler).set(eventType, unsubscribe);
88
+ }
89
+ off(eventType, handler) {
90
+ const handlerMap = this.unsubscribers.get(handler);
91
+ if (handlerMap) {
92
+ const unsubscribe = handlerMap.get(eventType);
93
+ if (unsubscribe) {
94
+ unsubscribe();
95
+ handlerMap.delete(eventType);
96
+ }
97
+ if (handlerMap.size === 0) {
98
+ this.unsubscribers.delete(handler);
99
+ }
100
+ }
101
+ }
102
+ async close() {
103
+ await this.inner.destroy();
104
+ this.unsubscribers.clear();
105
+ }
106
+ }
107
+ /**
108
+ * SquadClient wraps CopilotClient with enhanced lifecycle management.
109
+ *
110
+ * Features:
111
+ * - Connection state tracking
112
+ * - Automatic reconnection with exponential backoff
113
+ * - Protocol version validation
114
+ * - Error recovery
115
+ * - Session lifecycle event handling
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const client = new SquadClient();
120
+ * await client.connect();
121
+ *
122
+ * const session = await client.createSession({
123
+ * model: "claude-sonnet-4.5"
124
+ * });
125
+ *
126
+ * await client.disconnect();
127
+ * ```
128
+ */
129
+ export class SquadClient {
130
+ client;
131
+ state = "disconnected";
132
+ connectPromise = null;
133
+ reconnectAttempts = 0;
134
+ reconnectTimer = null;
135
+ options;
136
+ manualDisconnect = false;
137
+ /**
138
+ * Creates a new SquadClient instance.
139
+ *
140
+ * @param options - Configuration options
141
+ * @throws Error if mutually exclusive options are provided
142
+ */
143
+ constructor(options = {}) {
144
+ this.options = {
145
+ cliPath: options.cliPath,
146
+ cliArgs: options.cliArgs ?? [],
147
+ cwd: options.cwd ?? process.cwd(),
148
+ port: options.port ?? 0,
149
+ useStdio: options.useStdio ?? true,
150
+ cliUrl: options.cliUrl,
151
+ logLevel: options.logLevel ?? "debug",
152
+ autoStart: options.autoStart ?? true,
153
+ autoReconnect: options.autoReconnect ?? true,
154
+ env: options.env ?? process.env,
155
+ githubToken: options.githubToken,
156
+ useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
157
+ maxReconnectAttempts: options.maxReconnectAttempts ?? 3,
158
+ reconnectDelayMs: options.reconnectDelayMs ?? 1000,
159
+ };
160
+ this.client = new CopilotClient({
161
+ cliPath: this.options.cliPath,
162
+ cliArgs: this.options.cliArgs,
163
+ cwd: this.options.cwd,
164
+ port: this.options.port,
165
+ useStdio: this.options.useStdio,
166
+ cliUrl: this.options.cliUrl,
167
+ logLevel: this.options.logLevel,
168
+ autoStart: false, // We manage connection lifecycle
169
+ autoRestart: false, // We handle reconnection ourselves
170
+ env: this.options.env,
171
+ githubToken: this.options.githubToken,
172
+ useLoggedInUser: this.options.useLoggedInUser,
173
+ });
174
+ }
175
+ /**
176
+ * Get the current connection state.
177
+ */
178
+ getState() {
179
+ return this.state;
180
+ }
181
+ /**
182
+ * Check if the client is connected.
183
+ */
184
+ isConnected() {
185
+ return this.state === "connected";
186
+ }
187
+ /**
188
+ * Establish connection to the Copilot CLI server.
189
+ *
190
+ * This method:
191
+ * 1. Spawns or connects to the CLI server
192
+ * 2. Validates protocol version compatibility
193
+ * 3. Sets up automatic reconnection handlers
194
+ *
195
+ * @returns Promise that resolves when connection is established
196
+ * @throws Error if connection fails or protocol version is incompatible
197
+ */
198
+ async connect() {
199
+ if (this.state === "connected") {
200
+ return;
201
+ }
202
+ // Dedup: if a connection is already in progress, piggyback on it
203
+ if (this.state === "connecting" && this.connectPromise) {
204
+ return this.connectPromise;
205
+ }
206
+ const span = tracer.startSpan('squad.client.connect');
207
+ span.setAttribute('connection.transport', this.options.useStdio ? 'stdio' : 'tcp');
208
+ this.state = "connecting";
209
+ this.manualDisconnect = false;
210
+ this.connectPromise = (async () => {
211
+ const startTime = Date.now();
212
+ try {
213
+ await this.client.start();
214
+ const elapsed = Date.now() - startTime;
215
+ this.state = "connected";
216
+ this.reconnectAttempts = 0;
217
+ span.setAttribute('connection.duration_ms', elapsed);
218
+ if (elapsed > 2000) {
219
+ console.warn(`SquadClient connection took ${elapsed}ms (> 2s threshold)`);
220
+ }
221
+ }
222
+ catch (error) {
223
+ this.state = "error";
224
+ const wrapped = new Error(`Failed to connect to Copilot CLI: ${error instanceof Error ? error.message : String(error)}`);
225
+ span.setStatus({ code: SpanStatusCode.ERROR, message: wrapped.message });
226
+ span.recordException(wrapped);
227
+ throw wrapped;
228
+ }
229
+ finally {
230
+ this.connectPromise = null;
231
+ span.end();
232
+ }
233
+ })();
234
+ return this.connectPromise;
235
+ }
236
+ /**
237
+ * Disconnect from the Copilot CLI server.
238
+ *
239
+ * Performs graceful cleanup:
240
+ * 1. Destroys all active sessions
241
+ * 2. Closes the connection
242
+ * 3. Terminates the CLI process (if spawned)
243
+ *
244
+ * @returns Promise that resolves with any errors encountered during cleanup
245
+ */
246
+ async disconnect() {
247
+ const span = tracer.startSpan('squad.client.disconnect');
248
+ try {
249
+ this.manualDisconnect = true;
250
+ if (this.reconnectTimer) {
251
+ clearTimeout(this.reconnectTimer);
252
+ this.reconnectTimer = null;
253
+ }
254
+ const errors = await this.client.stop();
255
+ this.state = "disconnected";
256
+ this.reconnectAttempts = 0;
257
+ this.connectPromise = null;
258
+ return errors;
259
+ }
260
+ catch (err) {
261
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
262
+ span.recordException(err instanceof Error ? err : new Error(String(err)));
263
+ throw err;
264
+ }
265
+ finally {
266
+ span.end();
267
+ }
268
+ }
269
+ /**
270
+ * Force disconnect without graceful cleanup.
271
+ * Use only when disconnect() fails or hangs.
272
+ */
273
+ async forceDisconnect() {
274
+ this.manualDisconnect = true;
275
+ if (this.reconnectTimer) {
276
+ clearTimeout(this.reconnectTimer);
277
+ this.reconnectTimer = null;
278
+ }
279
+ await this.client.forceStop();
280
+ this.state = "disconnected";
281
+ this.reconnectAttempts = 0;
282
+ this.connectPromise = null;
283
+ }
284
+ /**
285
+ * Create a new Squad session.
286
+ *
287
+ * If autoStart is enabled and the client is not connected, this will
288
+ * automatically establish the connection.
289
+ *
290
+ * @param config - Session configuration
291
+ * @returns Promise that resolves with the created session
292
+ */
293
+ async createSession(config = {}) {
294
+ const span = tracer.startSpan('squad.session.create');
295
+ span.setAttribute('session.auto_start', this.options.autoStart);
296
+ try {
297
+ if (!this.isConnected() && this.options.autoStart) {
298
+ await this.connect();
299
+ }
300
+ if (!this.isConnected()) {
301
+ throw new Error("Client not connected. Call connect() first.");
302
+ }
303
+ try {
304
+ // Cast config to handle SDK version differences in SessionConfig type
305
+ const session = await this.client.createSession(config);
306
+ const result = new CopilotSessionAdapter(session);
307
+ if (result.sessionId) {
308
+ span.setAttribute('session.id', result.sessionId);
309
+ }
310
+ recordSessionCreated();
311
+ return result;
312
+ }
313
+ catch (error) {
314
+ const msg = error instanceof Error ? error.message : String(error);
315
+ if (msg.includes('onPermissionRequest')) {
316
+ throw new Error('Session creation failed: an onPermissionRequest handler is required. ' +
317
+ 'Pass { onPermissionRequest: () => ({ kind: "approved" }) } in your session config ' +
318
+ 'to approve all permissions, or provide a custom handler.');
319
+ }
320
+ recordSessionError();
321
+ if (this.shouldAttemptReconnect(error)) {
322
+ await this.attemptReconnection();
323
+ return this.createSession(config);
324
+ }
325
+ throw error;
326
+ }
327
+ }
328
+ catch (err) {
329
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
330
+ span.recordException(err instanceof Error ? err : new Error(String(err)));
331
+ throw err;
332
+ }
333
+ finally {
334
+ span.end();
335
+ }
336
+ }
337
+ /**
338
+ * Resume an existing Squad session by ID.
339
+ *
340
+ * @param sessionId - ID of the session to resume
341
+ * @param config - Optional configuration overrides
342
+ * @returns Promise that resolves with the resumed session
343
+ */
344
+ async resumeSession(sessionId, config = {}) {
345
+ const span = tracer.startSpan('squad.session.resume');
346
+ span.setAttribute('session.id', sessionId);
347
+ try {
348
+ if (!this.isConnected() && this.options.autoStart) {
349
+ await this.connect();
350
+ }
351
+ if (!this.isConnected()) {
352
+ throw new Error("Client not connected. Call connect() first.");
353
+ }
354
+ try {
355
+ // Cast config to handle SDK version differences in ResumeSessionConfig type
356
+ const session = await this.client.resumeSession(sessionId, config);
357
+ return new CopilotSessionAdapter(session);
358
+ }
359
+ catch (error) {
360
+ if (this.shouldAttemptReconnect(error)) {
361
+ await this.attemptReconnection();
362
+ return this.resumeSession(sessionId, config);
363
+ }
364
+ throw error;
365
+ }
366
+ }
367
+ catch (err) {
368
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
369
+ span.recordException(err instanceof Error ? err : new Error(String(err)));
370
+ throw err;
371
+ }
372
+ finally {
373
+ span.end();
374
+ }
375
+ }
376
+ /**
377
+ * List all available sessions.
378
+ */
379
+ async listSessions() {
380
+ const span = tracer.startSpan('squad.session.list');
381
+ try {
382
+ if (!this.isConnected()) {
383
+ throw new Error("Client not connected");
384
+ }
385
+ try {
386
+ const sessions = await this.client.listSessions();
387
+ const result = sessions.map((s) => ({
388
+ sessionId: s.sessionId,
389
+ startTime: s.startTime,
390
+ modifiedTime: s.modifiedTime,
391
+ summary: s.summary,
392
+ isRemote: s.isRemote,
393
+ context: s.context,
394
+ }));
395
+ span.setAttribute('sessions.count', result.length);
396
+ return result;
397
+ }
398
+ catch (error) {
399
+ if (this.shouldAttemptReconnect(error)) {
400
+ await this.attemptReconnection();
401
+ return this.listSessions();
402
+ }
403
+ throw error;
404
+ }
405
+ }
406
+ catch (err) {
407
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
408
+ span.recordException(err instanceof Error ? err : new Error(String(err)));
409
+ throw err;
410
+ }
411
+ finally {
412
+ span.end();
413
+ }
414
+ }
415
+ /**
416
+ * Delete a session by ID.
417
+ */
418
+ async deleteSession(sessionId) {
419
+ const span = tracer.startSpan('squad.session.delete');
420
+ span.setAttribute('session.id', sessionId);
421
+ try {
422
+ if (!this.isConnected()) {
423
+ throw new Error("Client not connected");
424
+ }
425
+ try {
426
+ await this.client.deleteSession(sessionId);
427
+ recordSessionClosed();
428
+ }
429
+ catch (error) {
430
+ recordSessionError();
431
+ if (this.shouldAttemptReconnect(error)) {
432
+ await this.attemptReconnection();
433
+ return this.deleteSession(sessionId);
434
+ }
435
+ throw error;
436
+ }
437
+ }
438
+ catch (err) {
439
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
440
+ span.recordException(err instanceof Error ? err : new Error(String(err)));
441
+ throw err;
442
+ }
443
+ finally {
444
+ span.end();
445
+ }
446
+ }
447
+ /**
448
+ * Get the ID of the last updated session.
449
+ */
450
+ async getLastSessionId() {
451
+ if (!this.isConnected()) {
452
+ throw new Error("Client not connected");
453
+ }
454
+ try {
455
+ return await this.client.getLastSessionId();
456
+ }
457
+ catch (error) {
458
+ if (this.shouldAttemptReconnect(error)) {
459
+ await this.attemptReconnection();
460
+ return this.getLastSessionId();
461
+ }
462
+ throw error;
463
+ }
464
+ }
465
+ /**
466
+ * Send a ping to verify connectivity.
467
+ */
468
+ async ping(message) {
469
+ if (!this.isConnected()) {
470
+ throw new Error("Client not connected");
471
+ }
472
+ try {
473
+ return await this.client.ping(message);
474
+ }
475
+ catch (error) {
476
+ if (this.shouldAttemptReconnect(error)) {
477
+ await this.attemptReconnection();
478
+ return this.ping(message);
479
+ }
480
+ throw error;
481
+ }
482
+ }
483
+ /**
484
+ * Get CLI status information.
485
+ */
486
+ async getStatus() {
487
+ if (!this.isConnected()) {
488
+ throw new Error("Client not connected");
489
+ }
490
+ try {
491
+ const raw = await this.client.getStatus();
492
+ return {
493
+ version: raw.version,
494
+ protocolVersion: raw.protocolVersion,
495
+ };
496
+ }
497
+ catch (error) {
498
+ if (this.shouldAttemptReconnect(error)) {
499
+ await this.attemptReconnection();
500
+ return this.getStatus();
501
+ }
502
+ throw error;
503
+ }
504
+ }
505
+ /**
506
+ * Get authentication status.
507
+ */
508
+ async getAuthStatus() {
509
+ if (!this.isConnected()) {
510
+ throw new Error("Client not connected");
511
+ }
512
+ try {
513
+ const raw = await this.client.getAuthStatus();
514
+ return {
515
+ isAuthenticated: raw.isAuthenticated,
516
+ authType: raw.authType,
517
+ host: raw.host,
518
+ login: raw.login,
519
+ statusMessage: raw.statusMessage,
520
+ };
521
+ }
522
+ catch (error) {
523
+ if (this.shouldAttemptReconnect(error)) {
524
+ await this.attemptReconnection();
525
+ return this.getAuthStatus();
526
+ }
527
+ throw error;
528
+ }
529
+ }
530
+ /**
531
+ * List available models.
532
+ */
533
+ async listModels() {
534
+ if (!this.isConnected()) {
535
+ throw new Error("Client not connected");
536
+ }
537
+ try {
538
+ const models = await this.client.listModels();
539
+ return models.map((m) => ({
540
+ id: m.id,
541
+ name: m.name,
542
+ capabilities: m.capabilities,
543
+ policy: m.policy,
544
+ billing: m.billing,
545
+ supportedReasoningEfforts: m.supportedReasoningEfforts,
546
+ defaultReasoningEffort: m.defaultReasoningEffort,
547
+ }));
548
+ }
549
+ catch (error) {
550
+ if (this.shouldAttemptReconnect(error)) {
551
+ await this.attemptReconnection();
552
+ return this.listModels();
553
+ }
554
+ throw error;
555
+ }
556
+ }
557
+ /**
558
+ * Send a message to a session, wrapped with OTel tracing.
559
+ *
560
+ * Creates a `squad.session.message` span for the full call and a
561
+ * child `squad.session.stream` span that tracks streaming duration
562
+ * with `first_token`, `last_token`, and `stream_error` events.
563
+ *
564
+ * @param session - The session to send the message to
565
+ * @param options - Message content and delivery options
566
+ * @returns Promise that resolves when the message is processed
567
+ */
568
+ async sendMessage(session, options) {
569
+ const messageSpan = tracer.startSpan('squad.session.message');
570
+ messageSpan.setAttribute('session.id', session.sessionId);
571
+ messageSpan.setAttribute('prompt.length', options.prompt.length);
572
+ messageSpan.setAttribute('streaming', true);
573
+ const streamSpan = tracer.startSpan('squad.session.stream');
574
+ streamSpan.setAttribute('session.id', session.sessionId);
575
+ const messageStartMs = Date.now();
576
+ let firstTokenRecorded = false;
577
+ let outputTokens = 0;
578
+ let inputTokens = 0;
579
+ const origOn = session.on.bind(session);
580
+ // Wire temporary event listener for stream tracking
581
+ const streamListener = (event) => {
582
+ if (event.type === 'message_delta' && !firstTokenRecorded) {
583
+ firstTokenRecorded = true;
584
+ streamSpan.addEvent('first_token');
585
+ }
586
+ if (event.type === 'usage') {
587
+ inputTokens = typeof event['inputTokens'] === 'number' ? event['inputTokens'] : 0;
588
+ outputTokens = typeof event['outputTokens'] === 'number' ? event['outputTokens'] : 0;
589
+ }
590
+ };
591
+ origOn('message_delta', streamListener);
592
+ origOn('usage', streamListener);
593
+ try {
594
+ await session.sendMessage(options);
595
+ const durationMs = Date.now() - messageStartMs;
596
+ streamSpan.addEvent('last_token');
597
+ streamSpan.setAttribute('tokens.input', inputTokens);
598
+ streamSpan.setAttribute('tokens.output', outputTokens);
599
+ streamSpan.setAttribute('duration_ms', durationMs);
600
+ }
601
+ catch (err) {
602
+ streamSpan.addEvent('stream_error');
603
+ streamSpan.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
604
+ streamSpan.recordException(err instanceof Error ? err : new Error(String(err)));
605
+ messageSpan.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
606
+ messageSpan.recordException(err instanceof Error ? err : new Error(String(err)));
607
+ throw err;
608
+ }
609
+ finally {
610
+ streamSpan.end();
611
+ messageSpan.end();
612
+ // Clean up listeners
613
+ try {
614
+ session.off('message_delta', streamListener);
615
+ session.off('usage', streamListener);
616
+ }
617
+ catch {
618
+ // session may not support off — ignore
619
+ }
620
+ }
621
+ }
622
+ /**
623
+ * Close a session (alias for deleteSession with `squad.session.close` span).
624
+ *
625
+ * @param sessionId - ID of the session to close
626
+ */
627
+ async closeSession(sessionId) {
628
+ const span = tracer.startSpan('squad.session.close');
629
+ span.setAttribute('session.id', sessionId);
630
+ try {
631
+ await this.deleteSession(sessionId);
632
+ }
633
+ catch (err) {
634
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
635
+ span.recordException(err instanceof Error ? err : new Error(String(err)));
636
+ throw err;
637
+ }
638
+ finally {
639
+ span.end();
640
+ }
641
+ }
642
+ on(eventTypeOrHandler, handler) {
643
+ if (typeof eventTypeOrHandler === "string" && handler) {
644
+ return this.client.on(eventTypeOrHandler, handler);
645
+ }
646
+ else {
647
+ return this.client.on(eventTypeOrHandler);
648
+ }
649
+ }
650
+ /**
651
+ * Determine if an error is recoverable via reconnection.
652
+ */
653
+ shouldAttemptReconnect(error) {
654
+ if (!this.options.autoReconnect) {
655
+ return false;
656
+ }
657
+ if (this.manualDisconnect) {
658
+ return false;
659
+ }
660
+ if (this.reconnectAttempts >= this.options.maxReconnectAttempts) {
661
+ return false;
662
+ }
663
+ const message = error instanceof Error ? error.message : String(error);
664
+ // Transient connection errors
665
+ if (message.includes("ECONNREFUSED") ||
666
+ message.includes("ECONNRESET") ||
667
+ message.includes("EPIPE") ||
668
+ message.includes("Client not connected") ||
669
+ message.includes("Connection closed")) {
670
+ return true;
671
+ }
672
+ return false;
673
+ }
674
+ /**
675
+ * Attempt to reconnect with exponential backoff.
676
+ */
677
+ async attemptReconnection() {
678
+ if (this.state === "reconnecting") {
679
+ throw new Error("Reconnection already in progress");
680
+ }
681
+ this.state = "reconnecting";
682
+ this.reconnectAttempts++;
683
+ const delay = this.options.reconnectDelayMs * Math.pow(2, this.reconnectAttempts - 1);
684
+ await new Promise((resolve) => {
685
+ this.reconnectTimer = setTimeout(resolve, delay);
686
+ });
687
+ try {
688
+ await this.client.stop();
689
+ await this.client.start();
690
+ this.state = "connected";
691
+ this.reconnectAttempts = 0;
692
+ }
693
+ catch (error) {
694
+ this.state = "error";
695
+ throw new Error(`Reconnection attempt ${this.reconnectAttempts} failed: ${error instanceof Error ? error.message : String(error)}`);
696
+ }
697
+ }
698
+ }
699
+ //# sourceMappingURL=client.js.map