@corbet-labs/ccht 0.2.0 → 0.2.2

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 (382) hide show
  1. package/README.md +194 -212
  2. package/index.d.ts +6 -1
  3. package/index.js +8 -1
  4. package/package.json +12 -26
  5. package/src/auth.ts +149 -0
  6. package/src/components/AccountConnection.svelte +201 -0
  7. package/src/components/Dock.svelte +172 -0
  8. package/src/dock.ts +244 -0
  9. package/wasm/ccht_bg.wasm +0 -0
  10. package/LICENSE +0 -307
  11. package/LICENSE.md +0 -25
  12. package/LICENSES/GPL-3.0-only.txt +0 -232
  13. package/LICENSES/LGPL-3.0-only.txt +0 -304
  14. package/LICENSES/dependencies/agent-client-protocol-2.1.0/LICENSE +0 -191
  15. package/LICENSES/dependencies/agent-client-protocol-derive-2.1.0/LICENSE +0 -191
  16. package/LICENSES/dependencies/agent-client-protocol-schema-1.7.0/LICENSE +0 -190
  17. package/LICENSES/dependencies/android_system_properties-0.1.6/LICENSE-APACHE +0 -13
  18. package/LICENSES/dependencies/android_system_properties-0.1.6/LICENSE-MIT +0 -20
  19. package/LICENSES/dependencies/anyhow-1.0.104/LICENSE-APACHE +0 -176
  20. package/LICENSES/dependencies/anyhow-1.0.104/LICENSE-MIT +0 -23
  21. package/LICENSES/dependencies/async-channel-2.5.0/LICENSE-APACHE +0 -201
  22. package/LICENSES/dependencies/async-channel-2.5.0/LICENSE-MIT +0 -23
  23. package/LICENSES/dependencies/async-io-2.6.0/LICENSE-APACHE +0 -201
  24. package/LICENSES/dependencies/async-io-2.6.0/LICENSE-MIT +0 -23
  25. package/LICENSES/dependencies/async-lock-3.4.2/LICENSE-APACHE +0 -201
  26. package/LICENSES/dependencies/async-lock-3.4.2/LICENSE-MIT +0 -23
  27. package/LICENSES/dependencies/async-process-2.5.0/LICENSE-APACHE +0 -201
  28. package/LICENSES/dependencies/async-process-2.5.0/LICENSE-MIT +0 -23
  29. package/LICENSES/dependencies/async-signal-0.2.14/LICENSE-APACHE +0 -201
  30. package/LICENSES/dependencies/async-signal-0.2.14/LICENSE-MIT +0 -23
  31. package/LICENSES/dependencies/async-task-4.7.1/LICENSE-APACHE +0 -201
  32. package/LICENSES/dependencies/async-task-4.7.1/LICENSE-MIT +0 -23
  33. package/LICENSES/dependencies/atomic-waker-1.1.2/LICENSE-APACHE +0 -201
  34. package/LICENSES/dependencies/atomic-waker-1.1.2/LICENSE-MIT +0 -23
  35. package/LICENSES/dependencies/atomic-waker-1.1.2/LICENSE-THIRD-PARTY +0 -45
  36. package/LICENSES/dependencies/autocfg-1.5.1/LICENSE-APACHE +0 -201
  37. package/LICENSES/dependencies/autocfg-1.5.1/LICENSE-MIT +0 -25
  38. package/LICENSES/dependencies/base64-0.22.1/LICENSE-APACHE +0 -201
  39. package/LICENSES/dependencies/base64-0.22.1/LICENSE-MIT +0 -21
  40. package/LICENSES/dependencies/base64-0.23.1/LICENSE-APACHE +0 -201
  41. package/LICENSES/dependencies/base64-0.23.1/LICENSE-MIT +0 -21
  42. package/LICENSES/dependencies/bitflags-1.3.2/LICENSE-APACHE +0 -201
  43. package/LICENSES/dependencies/bitflags-1.3.2/LICENSE-MIT +0 -25
  44. package/LICENSES/dependencies/bitflags-2.13.2/LICENSE-APACHE +0 -201
  45. package/LICENSES/dependencies/bitflags-2.13.2/LICENSE-MIT +0 -25
  46. package/LICENSES/dependencies/blocking-1.7.0/LICENSE-APACHE +0 -201
  47. package/LICENSES/dependencies/blocking-1.7.0/LICENSE-MIT +0 -23
  48. package/LICENSES/dependencies/bs58-0.5.1/LICENSE-APACHE +0 -201
  49. package/LICENSES/dependencies/bs58-0.5.1/LICENSE-MIT +0 -20
  50. package/LICENSES/dependencies/bumpalo-3.20.3/LICENSE-APACHE +0 -201
  51. package/LICENSES/dependencies/bumpalo-3.20.3/LICENSE-MIT +0 -25
  52. package/LICENSES/dependencies/cc-1.4.5/LICENSE-APACHE +0 -201
  53. package/LICENSES/dependencies/cc-1.4.5/LICENSE-MIT +0 -25
  54. package/LICENSES/dependencies/cfg-if-1.0.4/LICENSE-APACHE +0 -201
  55. package/LICENSES/dependencies/cfg-if-1.0.4/LICENSE-MIT +0 -25
  56. package/LICENSES/dependencies/chrono-0.4.45/LICENSE.txt +0 -240
  57. package/LICENSES/dependencies/concurrent-queue-2.5.0/LICENSE-APACHE +0 -201
  58. package/LICENSES/dependencies/concurrent-queue-2.5.0/LICENSE-MIT +0 -23
  59. package/LICENSES/dependencies/convert_case-0.10.0/LICENSE +0 -21
  60. package/LICENSES/dependencies/core-foundation-sys-0.8.7/LICENSE-APACHE +0 -201
  61. package/LICENSES/dependencies/core-foundation-sys-0.8.7/LICENSE-MIT +0 -25
  62. package/LICENSES/dependencies/crossbeam-deque-0.8.8/LICENSE-APACHE +0 -201
  63. package/LICENSES/dependencies/crossbeam-deque-0.8.8/LICENSE-MIT +0 -27
  64. package/LICENSES/dependencies/crossbeam-epoch-0.9.21/LICENSE-APACHE +0 -201
  65. package/LICENSES/dependencies/crossbeam-epoch-0.9.21/LICENSE-MIT +0 -27
  66. package/LICENSES/dependencies/crossbeam-utils-0.8.23/LICENSE-APACHE +0 -201
  67. package/LICENSES/dependencies/crossbeam-utils-0.8.23/LICENSE-MIT +0 -27
  68. package/LICENSES/dependencies/darling-0.24.1/LICENSE +0 -21
  69. package/LICENSES/dependencies/darling_core-0.24.1/LICENSE +0 -21
  70. package/LICENSES/dependencies/darling_macro-0.24.1/LICENSE +0 -21
  71. package/LICENSES/dependencies/defmt-1.1.1/LICENSE-APACHE +0 -201
  72. package/LICENSES/dependencies/defmt-1.1.1/LICENSE-MIT +0 -25
  73. package/LICENSES/dependencies/defmt-macros-1.1.1/LICENSE-APACHE +0 -201
  74. package/LICENSES/dependencies/defmt-macros-1.1.1/LICENSE-MIT +0 -25
  75. package/LICENSES/dependencies/defmt-parser-1.0.0/LICENSE-APACHE +0 -201
  76. package/LICENSES/dependencies/defmt-parser-1.0.0/LICENSE-MIT +0 -25
  77. package/LICENSES/dependencies/deranged-0.5.8/LICENSE-Apache +0 -202
  78. package/LICENSES/dependencies/deranged-0.5.8/LICENSE-MIT +0 -19
  79. package/LICENSES/dependencies/derive_more-2.1.1/LICENSE +0 -21
  80. package/LICENSES/dependencies/derive_more-impl-2.1.1/LICENSE +0 -21
  81. package/LICENSES/dependencies/dyn-clone-1.0.20/LICENSE-APACHE +0 -176
  82. package/LICENSES/dependencies/dyn-clone-1.0.20/LICENSE-MIT +0 -23
  83. package/LICENSES/dependencies/either-1.18.0/LICENSE-APACHE +0 -201
  84. package/LICENSES/dependencies/either-1.18.0/LICENSE-MIT +0 -25
  85. package/LICENSES/dependencies/equivalent-1.0.2/LICENSE-APACHE +0 -201
  86. package/LICENSES/dependencies/equivalent-1.0.2/LICENSE-MIT +0 -25
  87. package/LICENSES/dependencies/errno-0.3.14/LICENSE-APACHE +0 -201
  88. package/LICENSES/dependencies/errno-0.3.14/LICENSE-MIT +0 -25
  89. package/LICENSES/dependencies/event-listener-5.4.2/LICENSE-APACHE +0 -201
  90. package/LICENSES/dependencies/event-listener-5.4.2/LICENSE-MIT +0 -23
  91. package/LICENSES/dependencies/event-listener-strategy-0.5.4/LICENSE-APACHE +0 -201
  92. package/LICENSES/dependencies/event-listener-strategy-0.5.4/LICENSE-MIT +0 -23
  93. package/LICENSES/dependencies/fallible-iterator-0.3.0/LICENSE-APACHE +0 -202
  94. package/LICENSES/dependencies/fallible-iterator-0.3.0/LICENSE-MIT +0 -19
  95. package/LICENSES/dependencies/fastrand-2.5.0/LICENSE-APACHE +0 -201
  96. package/LICENSES/dependencies/fastrand-2.5.0/LICENSE-MIT +0 -23
  97. package/LICENSES/dependencies/find-msvc-tools-0.1.12/LICENSE-APACHE +0 -201
  98. package/LICENSES/dependencies/find-msvc-tools-0.1.12/LICENSE-MIT +0 -25
  99. package/LICENSES/dependencies/fixedbitset-0.5.7/LICENSE-APACHE +0 -201
  100. package/LICENSES/dependencies/fixedbitset-0.5.7/LICENSE-MIT +0 -25
  101. package/LICENSES/dependencies/foldhash-0.2.0/LICENSE +0 -19
  102. package/LICENSES/dependencies/futures-0.3.34/LICENSE-APACHE +0 -202
  103. package/LICENSES/dependencies/futures-0.3.34/LICENSE-MIT +0 -26
  104. package/LICENSES/dependencies/futures-channel-0.3.34/LICENSE-APACHE +0 -202
  105. package/LICENSES/dependencies/futures-channel-0.3.34/LICENSE-MIT +0 -26
  106. package/LICENSES/dependencies/futures-concurrency-7.7.1/LICENSE-APACHE +0 -190
  107. package/LICENSES/dependencies/futures-concurrency-7.7.1/LICENSE-MIT +0 -21
  108. package/LICENSES/dependencies/futures-core-0.3.34/LICENSE-APACHE +0 -202
  109. package/LICENSES/dependencies/futures-core-0.3.34/LICENSE-MIT +0 -26
  110. package/LICENSES/dependencies/futures-executor-0.3.34/LICENSE-APACHE +0 -202
  111. package/LICENSES/dependencies/futures-executor-0.3.34/LICENSE-MIT +0 -26
  112. package/LICENSES/dependencies/futures-io-0.3.34/LICENSE-APACHE +0 -202
  113. package/LICENSES/dependencies/futures-io-0.3.34/LICENSE-MIT +0 -26
  114. package/LICENSES/dependencies/futures-lite-2.6.1/LICENSE-APACHE +0 -201
  115. package/LICENSES/dependencies/futures-lite-2.6.1/LICENSE-MIT +0 -23
  116. package/LICENSES/dependencies/futures-lite-2.6.1/LICENSE-THIRD-PARTY +0 -45
  117. package/LICENSES/dependencies/futures-macro-0.3.34/LICENSE-APACHE +0 -202
  118. package/LICENSES/dependencies/futures-macro-0.3.34/LICENSE-MIT +0 -26
  119. package/LICENSES/dependencies/futures-sink-0.3.34/LICENSE-APACHE +0 -202
  120. package/LICENSES/dependencies/futures-sink-0.3.34/LICENSE-MIT +0 -26
  121. package/LICENSES/dependencies/futures-task-0.3.34/LICENSE-APACHE +0 -202
  122. package/LICENSES/dependencies/futures-task-0.3.34/LICENSE-MIT +0 -26
  123. package/LICENSES/dependencies/futures-util-0.3.34/LICENSE-APACHE +0 -202
  124. package/LICENSES/dependencies/futures-util-0.3.34/LICENSE-MIT +0 -26
  125. package/LICENSES/dependencies/getrandom-0.4.3/LICENSE-APACHE +0 -201
  126. package/LICENSES/dependencies/getrandom-0.4.3/LICENSE-MIT +0 -26
  127. package/LICENSES/dependencies/gimli-0.32.3/LICENSE-APACHE +0 -201
  128. package/LICENSES/dependencies/gimli-0.32.3/LICENSE-MIT +0 -25
  129. package/LICENSES/dependencies/hashbrown-0.12.3/LICENSE-APACHE +0 -201
  130. package/LICENSES/dependencies/hashbrown-0.12.3/LICENSE-MIT +0 -25
  131. package/LICENSES/dependencies/hashbrown-0.16.1/LICENSE-APACHE +0 -201
  132. package/LICENSES/dependencies/hashbrown-0.16.1/LICENSE-MIT +0 -25
  133. package/LICENSES/dependencies/hashbrown-0.17.1/LICENSE-APACHE +0 -201
  134. package/LICENSES/dependencies/hashbrown-0.17.1/LICENSE-MIT +0 -25
  135. package/LICENSES/dependencies/heck-0.5.0/LICENSE-APACHE +0 -201
  136. package/LICENSES/dependencies/heck-0.5.0/LICENSE-MIT +0 -25
  137. package/LICENSES/dependencies/hermit-abi-0.5.3/LICENSE-APACHE +0 -201
  138. package/LICENSES/dependencies/hermit-abi-0.5.3/LICENSE-MIT +0 -23
  139. package/LICENSES/dependencies/hex-0.4.3/LICENSE-APACHE +0 -202
  140. package/LICENSES/dependencies/hex-0.4.3/LICENSE-MIT +0 -20
  141. package/LICENSES/dependencies/iana-time-zone-0.1.65/LICENSE-APACHE +0 -201
  142. package/LICENSES/dependencies/iana-time-zone-0.1.65/LICENSE-MIT +0 -25
  143. package/LICENSES/dependencies/iana-time-zone-haiku-0.1.2/LICENSE-APACHE +0 -201
  144. package/LICENSES/dependencies/iana-time-zone-haiku-0.1.2/LICENSE-MIT +0 -25
  145. package/LICENSES/dependencies/id-arena-2.3.0/LICENSE-APACHE +0 -201
  146. package/LICENSES/dependencies/id-arena-2.3.0/LICENSE-MIT +0 -25
  147. package/LICENSES/dependencies/ident_case-1.0.1/LICENSE +0 -19
  148. package/LICENSES/dependencies/indexmap-1.9.3/LICENSE-APACHE +0 -201
  149. package/LICENSES/dependencies/indexmap-1.9.3/LICENSE-MIT +0 -25
  150. package/LICENSES/dependencies/indexmap-2.14.2/LICENSE-APACHE +0 -201
  151. package/LICENSES/dependencies/indexmap-2.14.2/LICENSE-MIT +0 -25
  152. package/LICENSES/dependencies/itoa-1.0.18/LICENSE-APACHE +0 -176
  153. package/LICENSES/dependencies/itoa-1.0.18/LICENSE-MIT +0 -23
  154. package/LICENSES/dependencies/jiff-0.2.35/COPYING +0 -3
  155. package/LICENSES/dependencies/jiff-0.2.35/LICENSE-MIT +0 -21
  156. package/LICENSES/dependencies/jiff-0.2.35/UNLICENSE +0 -24
  157. package/LICENSES/dependencies/jiff-core-0.1.0/COPYING +0 -3
  158. package/LICENSES/dependencies/jiff-core-0.1.0/LICENSE-MIT +0 -21
  159. package/LICENSES/dependencies/jiff-core-0.1.0/UNLICENSE +0 -24
  160. package/LICENSES/dependencies/jiff-static-0.2.35/COPYING +0 -3
  161. package/LICENSES/dependencies/jiff-static-0.2.35/LICENSE-MIT +0 -21
  162. package/LICENSES/dependencies/jiff-static-0.2.35/UNLICENSE +0 -24
  163. package/LICENSES/dependencies/jiff-tzdb-0.1.8/COPYING +0 -3
  164. package/LICENSES/dependencies/jiff-tzdb-0.1.8/LICENSE-MIT +0 -21
  165. package/LICENSES/dependencies/jiff-tzdb-0.1.8/UNLICENSE +0 -24
  166. package/LICENSES/dependencies/jiff-tzdb-platform-0.1.3/COPYING +0 -3
  167. package/LICENSES/dependencies/jiff-tzdb-platform-0.1.3/LICENSE-MIT +0 -21
  168. package/LICENSES/dependencies/jiff-tzdb-platform-0.1.3/UNLICENSE +0 -24
  169. package/LICENSES/dependencies/js-sys-0.3.105/LICENSE-APACHE +0 -201
  170. package/LICENSES/dependencies/js-sys-0.3.105/LICENSE-MIT +0 -25
  171. package/LICENSES/dependencies/leb128-0.2.7/LICENSE-APACHE +0 -201
  172. package/LICENSES/dependencies/leb128-0.2.7/LICENSE-MIT +0 -25
  173. package/LICENSES/dependencies/leb128fmt-0.1.0/LICENSE-APACHE +0 -201
  174. package/LICENSES/dependencies/leb128fmt-0.1.0/LICENSE-MIT +0 -23
  175. package/LICENSES/dependencies/libc-0.2.189/LICENSE-APACHE +0 -176
  176. package/LICENSES/dependencies/libc-0.2.189/LICENSE-MIT +0 -25
  177. package/LICENSES/dependencies/linux-raw-sys-0.12.1/COPYRIGHT +0 -29
  178. package/LICENSES/dependencies/linux-raw-sys-0.12.1/LICENSE-APACHE +0 -201
  179. package/LICENSES/dependencies/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
  180. package/LICENSES/dependencies/linux-raw-sys-0.12.1/LICENSE-MIT +0 -23
  181. package/LICENSES/dependencies/log-0.4.34/LICENSE-APACHE +0 -201
  182. package/LICENSES/dependencies/log-0.4.34/LICENSE-MIT +0 -25
  183. package/LICENSES/dependencies/memchr-2.8.3/COPYING +0 -3
  184. package/LICENSES/dependencies/memchr-2.8.3/LICENSE-MIT +0 -21
  185. package/LICENSES/dependencies/memchr-2.8.3/UNLICENSE +0 -24
  186. package/LICENSES/dependencies/mio-1.2.3/LICENSE +0 -19
  187. package/LICENSES/dependencies/num-conv-0.2.2/LICENSE-Apache +0 -177
  188. package/LICENSES/dependencies/num-conv-0.2.2/LICENSE-MIT +0 -19
  189. package/LICENSES/dependencies/num-traits-0.2.19/LICENSE-APACHE +0 -201
  190. package/LICENSES/dependencies/num-traits-0.2.19/LICENSE-MIT +0 -25
  191. package/LICENSES/dependencies/once_cell-1.21.4/LICENSE-APACHE +0 -201
  192. package/LICENSES/dependencies/once_cell-1.21.4/LICENSE-MIT +0 -23
  193. package/LICENSES/dependencies/parking-2.2.1/LICENSE-APACHE +0 -201
  194. package/LICENSES/dependencies/parking-2.2.1/LICENSE-MIT +0 -23
  195. package/LICENSES/dependencies/parking-2.2.1/LICENSE-THIRD-PARTY +0 -9
  196. package/LICENSES/dependencies/pin-project-1.1.13/LICENSE-APACHE +0 -177
  197. package/LICENSES/dependencies/pin-project-1.1.13/LICENSE-MIT +0 -23
  198. package/LICENSES/dependencies/pin-project-internal-1.1.13/LICENSE-APACHE +0 -177
  199. package/LICENSES/dependencies/pin-project-internal-1.1.13/LICENSE-MIT +0 -23
  200. package/LICENSES/dependencies/pin-project-lite-0.2.17/LICENSE-APACHE +0 -177
  201. package/LICENSES/dependencies/pin-project-lite-0.2.17/LICENSE-MIT +0 -23
  202. package/LICENSES/dependencies/piper-0.2.5/LICENSE-APACHE +0 -201
  203. package/LICENSES/dependencies/piper-0.2.5/LICENSE-MIT +0 -23
  204. package/LICENSES/dependencies/polling-3.11.0/LICENSE-APACHE +0 -201
  205. package/LICENSES/dependencies/polling-3.11.0/LICENSE-MIT +0 -23
  206. package/LICENSES/dependencies/portable-atomic-1.15.0/LICENSE-APACHE +0 -177
  207. package/LICENSES/dependencies/portable-atomic-1.15.0/LICENSE-MIT +0 -23
  208. package/LICENSES/dependencies/portable-atomic-util-0.2.8/LICENSE-APACHE +0 -177
  209. package/LICENSES/dependencies/portable-atomic-util-0.2.8/LICENSE-MIT +0 -23
  210. package/LICENSES/dependencies/powerfmt-0.2.0/LICENSE-Apache +0 -202
  211. package/LICENSES/dependencies/powerfmt-0.2.0/LICENSE-MIT +0 -19
  212. package/LICENSES/dependencies/proc-macro2-1.0.107/LICENSE-APACHE +0 -176
  213. package/LICENSES/dependencies/proc-macro2-1.0.107/LICENSE-MIT +0 -23
  214. package/LICENSES/dependencies/quote-1.0.47/LICENSE-APACHE +0 -176
  215. package/LICENSES/dependencies/quote-1.0.47/LICENSE-MIT +0 -23
  216. package/LICENSES/dependencies/r-efi-6.0.0/AUTHORS +0 -75
  217. package/LICENSES/dependencies/rayon-1.12.0/LICENSE-APACHE +0 -201
  218. package/LICENSES/dependencies/rayon-1.12.0/LICENSE-MIT +0 -25
  219. package/LICENSES/dependencies/rayon-core-1.13.0/LICENSE-APACHE +0 -201
  220. package/LICENSES/dependencies/rayon-core-1.13.0/LICENSE-MIT +0 -25
  221. package/LICENSES/dependencies/ref-cast-1.0.27/LICENSE-APACHE +0 -176
  222. package/LICENSES/dependencies/ref-cast-1.0.27/LICENSE-MIT +0 -23
  223. package/LICENSES/dependencies/ref-cast-impl-1.0.27/LICENSE-APACHE +0 -176
  224. package/LICENSES/dependencies/ref-cast-impl-1.0.27/LICENSE-MIT +0 -23
  225. package/LICENSES/dependencies/rustc-demangle-0.1.28/LICENSE-APACHE +0 -201
  226. package/LICENSES/dependencies/rustc-demangle-0.1.28/LICENSE-MIT +0 -25
  227. package/LICENSES/dependencies/rustc-hash-2.1.3/LICENSE-APACHE +0 -176
  228. package/LICENSES/dependencies/rustc-hash-2.1.3/LICENSE-MIT +0 -23
  229. package/LICENSES/dependencies/rustc_version-0.4.1/LICENSE-APACHE +0 -201
  230. package/LICENSES/dependencies/rustc_version-0.4.1/LICENSE-MIT +0 -25
  231. package/LICENSES/dependencies/rustix-1.1.4/COPYRIGHT +0 -29
  232. package/LICENSES/dependencies/rustix-1.1.4/LICENSE-APACHE +0 -201
  233. package/LICENSES/dependencies/rustix-1.1.4/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
  234. package/LICENSES/dependencies/rustix-1.1.4/LICENSE-MIT +0 -23
  235. package/LICENSES/dependencies/rustversion-1.0.23/LICENSE-APACHE +0 -176
  236. package/LICENSES/dependencies/rustversion-1.0.23/LICENSE-MIT +0 -23
  237. package/LICENSES/dependencies/schemars-0.9.0/LICENSE +0 -21
  238. package/LICENSES/dependencies/schemars-1.2.2/LICENSE +0 -21
  239. package/LICENSES/dependencies/schemars_derive-1.2.2/LICENSE +0 -21
  240. package/LICENSES/dependencies/semver-1.0.28/LICENSE-APACHE +0 -176
  241. package/LICENSES/dependencies/semver-1.0.28/LICENSE-MIT +0 -23
  242. package/LICENSES/dependencies/serde-1.0.229/LICENSE-APACHE +0 -176
  243. package/LICENSES/dependencies/serde-1.0.229/LICENSE-MIT +0 -23
  244. package/LICENSES/dependencies/serde_core-1.0.229/LICENSE-APACHE +0 -176
  245. package/LICENSES/dependencies/serde_core-1.0.229/LICENSE-MIT +0 -23
  246. package/LICENSES/dependencies/serde_derive-1.0.229/LICENSE-APACHE +0 -176
  247. package/LICENSES/dependencies/serde_derive-1.0.229/LICENSE-MIT +0 -23
  248. package/LICENSES/dependencies/serde_derive_internals-0.30.0/LICENSE-APACHE +0 -176
  249. package/LICENSES/dependencies/serde_derive_internals-0.30.0/LICENSE-MIT +0 -23
  250. package/LICENSES/dependencies/serde_json-1.0.151/LICENSE-APACHE +0 -176
  251. package/LICENSES/dependencies/serde_json-1.0.151/LICENSE-MIT +0 -23
  252. package/LICENSES/dependencies/serde_with-3.23.0/LICENSE-APACHE +0 -201
  253. package/LICENSES/dependencies/serde_with-3.23.0/LICENSE-MIT +0 -25
  254. package/LICENSES/dependencies/serde_with_macros-3.23.0/LICENSE-APACHE +0 -201
  255. package/LICENSES/dependencies/serde_with_macros-3.23.0/LICENSE-MIT +0 -25
  256. package/LICENSES/dependencies/shell-words-1.1.1/LICENSE-APACHE +0 -201
  257. package/LICENSES/dependencies/shell-words-1.1.1/LICENSE-MIT +0 -25
  258. package/LICENSES/dependencies/shlex-2.0.1/LICENSE-APACHE +0 -13
  259. package/LICENSES/dependencies/shlex-2.0.1/LICENSE-MIT +0 -21
  260. package/LICENSES/dependencies/signal-hook-registry-1.4.8/LICENSE-APACHE +0 -201
  261. package/LICENSES/dependencies/signal-hook-registry-1.4.8/LICENSE-MIT +0 -25
  262. package/LICENSES/dependencies/slab-0.4.12/LICENSE +0 -25
  263. package/LICENSES/dependencies/smallvec-1.16.0/LICENSE-APACHE +0 -201
  264. package/LICENSES/dependencies/smallvec-1.16.0/LICENSE-MIT +0 -25
  265. package/LICENSES/dependencies/socket2-0.6.5/LICENSE-APACHE +0 -201
  266. package/LICENSES/dependencies/socket2-0.6.5/LICENSE-MIT +0 -25
  267. package/LICENSES/dependencies/stable_deref_trait-1.2.1/LICENSE-APACHE +0 -201
  268. package/LICENSES/dependencies/stable_deref_trait-1.2.1/LICENSE-MIT +0 -25
  269. package/LICENSES/dependencies/strsim-0.11.1/LICENSE +0 -23
  270. package/LICENSES/dependencies/strum-0.28.0/LICENSE +0 -21
  271. package/LICENSES/dependencies/strum_macros-0.28.0/LICENSE +0 -21
  272. package/LICENSES/dependencies/syn-2.0.119/LICENSE-APACHE +0 -176
  273. package/LICENSES/dependencies/syn-2.0.119/LICENSE-MIT +0 -23
  274. package/LICENSES/dependencies/syn-3.0.5/LICENSE-APACHE +0 -176
  275. package/LICENSES/dependencies/syn-3.0.5/LICENSE-MIT +0 -23
  276. package/LICENSES/dependencies/thiserror-2.0.20/LICENSE-APACHE +0 -176
  277. package/LICENSES/dependencies/thiserror-2.0.20/LICENSE-MIT +0 -23
  278. package/LICENSES/dependencies/thiserror-impl-2.0.20/LICENSE-APACHE +0 -176
  279. package/LICENSES/dependencies/thiserror-impl-2.0.20/LICENSE-MIT +0 -23
  280. package/LICENSES/dependencies/time-0.3.55/LICENSE-Apache +0 -177
  281. package/LICENSES/dependencies/time-0.3.55/LICENSE-MIT +0 -19
  282. package/LICENSES/dependencies/time-core-0.1.9/LICENSE-Apache +0 -177
  283. package/LICENSES/dependencies/time-core-0.1.9/LICENSE-MIT +0 -19
  284. package/LICENSES/dependencies/time-macros-0.2.32/LICENSE-Apache +0 -177
  285. package/LICENSES/dependencies/time-macros-0.2.32/LICENSE-MIT +0 -19
  286. package/LICENSES/dependencies/tinyvec-1.13.2/LICENSE-APACHE.md +0 -202
  287. package/LICENSES/dependencies/tinyvec-1.13.2/LICENSE-MIT.md +0 -5
  288. package/LICENSES/dependencies/tinyvec-1.13.2/LICENSE-ZLIB.md +0 -11
  289. package/LICENSES/dependencies/tinyvec_macros-0.1.1/LICENSE-APACHE.md +0 -202
  290. package/LICENSES/dependencies/tinyvec_macros-0.1.1/LICENSE-MIT.md +0 -21
  291. package/LICENSES/dependencies/tinyvec_macros-0.1.1/LICENSE-ZLIB.md +0 -20
  292. package/LICENSES/dependencies/tokio-1.53.1/LICENSE +0 -21
  293. package/LICENSES/dependencies/tokio-macros-2.7.2/LICENSE +0 -22
  294. package/LICENSES/dependencies/tracing-0.1.44/LICENSE +0 -25
  295. package/LICENSES/dependencies/tracing-attributes-0.1.31/LICENSE +0 -25
  296. package/LICENSES/dependencies/tracing-core-0.1.36/LICENSE +0 -25
  297. package/LICENSES/dependencies/unicode-ident-1.0.24/LICENSE-APACHE +0 -176
  298. package/LICENSES/dependencies/unicode-ident-1.0.24/LICENSE-MIT +0 -23
  299. package/LICENSES/dependencies/unicode-ident-1.0.24/LICENSE-UNICODE +0 -39
  300. package/LICENSES/dependencies/unicode-segmentation-1.13.3/COPYRIGHT +0 -7
  301. package/LICENSES/dependencies/unicode-segmentation-1.13.3/LICENSE-APACHE +0 -201
  302. package/LICENSES/dependencies/unicode-segmentation-1.13.3/LICENSE-MIT +0 -25
  303. package/LICENSES/dependencies/unicode-xid-0.2.6/COPYRIGHT +0 -7
  304. package/LICENSES/dependencies/unicode-xid-0.2.6/LICENSE-APACHE +0 -201
  305. package/LICENSES/dependencies/unicode-xid-0.2.6/LICENSE-MIT +0 -25
  306. package/LICENSES/dependencies/uuid-1.26.1/LICENSE-APACHE +0 -201
  307. package/LICENSES/dependencies/uuid-1.26.1/LICENSE-MIT +0 -26
  308. package/LICENSES/dependencies/walrus-0.26.5/LICENSE-APACHE +0 -201
  309. package/LICENSES/dependencies/walrus-0.26.5/LICENSE-MIT +0 -25
  310. package/LICENSES/dependencies/walrus-macro-0.26.0/LICENSE-APACHE +0 -201
  311. package/LICENSES/dependencies/walrus-macro-0.26.0/LICENSE-MIT +0 -25
  312. package/LICENSES/dependencies/wasi-0.11.1+wasi-snapshot-preview1/LICENSE-APACHE +0 -201
  313. package/LICENSES/dependencies/wasi-0.11.1+wasi-snapshot-preview1/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
  314. package/LICENSES/dependencies/wasi-0.11.1+wasi-snapshot-preview1/LICENSE-MIT +0 -23
  315. package/LICENSES/dependencies/wasm-bindgen-0.2.128/LICENSE-APACHE +0 -201
  316. package/LICENSES/dependencies/wasm-bindgen-0.2.128/LICENSE-MIT +0 -25
  317. package/LICENSES/dependencies/wasm-bindgen-cli-support-0.2.128/LICENSE-APACHE +0 -201
  318. package/LICENSES/dependencies/wasm-bindgen-cli-support-0.2.128/LICENSE-MIT +0 -25
  319. package/LICENSES/dependencies/wasm-bindgen-macro-0.2.128/LICENSE-APACHE +0 -201
  320. package/LICENSES/dependencies/wasm-bindgen-macro-0.2.128/LICENSE-MIT +0 -25
  321. package/LICENSES/dependencies/wasm-bindgen-macro-support-0.2.128/LICENSE-APACHE +0 -201
  322. package/LICENSES/dependencies/wasm-bindgen-macro-support-0.2.128/LICENSE-MIT +0 -25
  323. package/LICENSES/dependencies/wasm-bindgen-shared-0.2.128/LICENSE-APACHE +0 -201
  324. package/LICENSES/dependencies/wasm-bindgen-shared-0.2.128/LICENSE-MIT +0 -25
  325. package/LICENSES/dependencies/wasm-encoder-0.245.1/LICENSE-APACHE +0 -201
  326. package/LICENSES/dependencies/wasm-encoder-0.245.1/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
  327. package/LICENSES/dependencies/wasm-encoder-0.245.1/LICENSE-MIT +0 -23
  328. package/LICENSES/dependencies/wasmparser-0.245.1/LICENSE-APACHE +0 -201
  329. package/LICENSES/dependencies/wasmparser-0.245.1/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
  330. package/LICENSES/dependencies/wasmparser-0.245.1/LICENSE-MIT +0 -23
  331. package/LICENSES/dependencies/windows-core-0.62.2/license-apache-2.0 +0 -201
  332. package/LICENSES/dependencies/windows-core-0.62.2/license-mit +0 -21
  333. package/LICENSES/dependencies/windows-implement-0.60.2/license-apache-2.0 +0 -201
  334. package/LICENSES/dependencies/windows-implement-0.60.2/license-mit +0 -21
  335. package/LICENSES/dependencies/windows-interface-0.59.3/license-apache-2.0 +0 -201
  336. package/LICENSES/dependencies/windows-interface-0.59.3/license-mit +0 -21
  337. package/LICENSES/dependencies/windows-link-0.2.1/license-apache-2.0 +0 -201
  338. package/LICENSES/dependencies/windows-link-0.2.1/license-mit +0 -21
  339. package/LICENSES/dependencies/windows-result-0.4.1/license-apache-2.0 +0 -201
  340. package/LICENSES/dependencies/windows-result-0.4.1/license-mit +0 -21
  341. package/LICENSES/dependencies/windows-strings-0.5.1/license-apache-2.0 +0 -201
  342. package/LICENSES/dependencies/windows-strings-0.5.1/license-mit +0 -21
  343. package/LICENSES/dependencies/windows-sys-0.61.2/license-apache-2.0 +0 -201
  344. package/LICENSES/dependencies/windows-sys-0.61.2/license-mit +0 -21
  345. package/LICENSES/dependencies/zmij-1.0.23/LICENSE-MIT +0 -23
  346. package/THIRD-PARTY.md +0 -45
  347. package/source/.cargo/config.toml +0 -5
  348. package/source/.ci/upstream-notices/PROVENANCE.json +0 -198
  349. package/source/.ci/upstream-notices/agent-client-protocol-2.1.0/LICENSE +0 -191
  350. package/source/.ci/upstream-notices/agent-client-protocol-derive-2.1.0/LICENSE +0 -191
  351. package/source/.ci/upstream-notices/agent-client-protocol-schema-1.7.0/LICENSE +0 -190
  352. package/source/.ci/upstream-notices/defmt-parser-1.0.0/LICENSE-APACHE +0 -201
  353. package/source/.ci/upstream-notices/defmt-parser-1.0.0/LICENSE-MIT +0 -25
  354. package/source/.ci/upstream-notices/r-efi-6.0.0/AUTHORS +0 -75
  355. package/source/.ci/upstream-notices/wasm-encoder-0.245.1/LICENSE-APACHE +0 -201
  356. package/source/.ci/upstream-notices/wasm-encoder-0.245.1/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
  357. package/source/.ci/upstream-notices/wasm-encoder-0.245.1/LICENSE-MIT +0 -23
  358. package/source/.ci/upstream-notices/wasmparser-0.245.1/LICENSE-APACHE +0 -201
  359. package/source/.ci/upstream-notices/wasmparser-0.245.1/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
  360. package/source/.ci/upstream-notices/wasmparser-0.245.1/LICENSE-MIT +0 -23
  361. package/source/.ci/wasm-bundle/Cargo.toml +0 -10
  362. package/source/.ci/wasm-bundle/src/main.rs +0 -17
  363. package/source/CHANGELOG.md +0 -28
  364. package/source/Cargo.lock +0 -1622
  365. package/source/Cargo.toml +0 -48
  366. package/source/LICENSE +0 -307
  367. package/source/LICENSE.md +0 -25
  368. package/source/LICENSES/GPL-3.0-only.txt +0 -232
  369. package/source/LICENSES/LGPL-3.0-only.txt +0 -304
  370. package/source/README.md +0 -234
  371. package/source/THIRD-PARTY.md +0 -45
  372. package/source/dependencies.tar.gz +0 -0
  373. package/source/examples/native.rs +0 -45
  374. package/source/src/configuration.rs +0 -89
  375. package/source/src/conversation.rs +0 -569
  376. package/source/src/lib.rs +0 -30
  377. package/source/src/native/client.rs +0 -395
  378. package/source/src/native/fixture.py +0 -114
  379. package/source/src/native/mod.rs +0 -252
  380. package/source/src/native/session.rs +0 -603
  381. package/source/src/native/tests.rs +0 -463
  382. package/source/src/web.rs +0 -35
@@ -1,603 +0,0 @@
1
- use std::collections::BTreeMap;
2
- use std::sync::atomic::{AtomicU64, Ordering};
3
- use std::sync::{Arc, Mutex};
4
-
5
- use agent_client_protocol::util::MatchDispatch;
6
- use agent_client_protocol::{ActiveSession, Agent, Dispatch, Responder, SessionMessage};
7
- use tokio::sync::{mpsc, oneshot, watch};
8
- use tokio::task::JoinHandle;
9
- use tokio::time::{Instant, interval, timeout};
10
-
11
- use crate::acp::{
12
- CancelNotification, CloseSessionRequest, ContentBlock, PromptRequest, PromptResponse,
13
- RequestPermissionOutcome, RequestPermissionRequest, RequestPermissionResponse, SessionId,
14
- SessionNotification, StopReason,
15
- };
16
- use crate::{Event, Prompt, SessionConfiguration, SessionEvent};
17
-
18
- use super::client::{ClientLease, ClientState};
19
- use super::{NativeError, PermissionDecision, PermissionPolicy, Result, lock};
20
-
21
- static NEXT_PERMISSION: AtomicU64 = AtomicU64::new(1);
22
-
23
- /// A native session and its single ordered event stream.
24
- ///
25
- /// Take the receiver once, then retain a handle while consuming it. A cloned
26
- /// handle keeps the session alive independently of this value.
27
- pub struct NativeSession {
28
- handle: SessionHandle,
29
- events: Option<mpsc::Receiver<SessionEvent>>,
30
- }
31
-
32
- /// Cloneable, thread-safe control of a native conversation.
33
- #[derive(Clone)]
34
- pub struct SessionHandle {
35
- lease: Arc<SessionLease>,
36
- }
37
-
38
- struct SessionLease {
39
- state: Arc<SessionState>,
40
- commands: mpsc::Sender<PromptCommand>,
41
- client: Arc<ClientLease>,
42
- }
43
-
44
- struct SessionState {
45
- id: SessionId,
46
- client: Arc<ClientState>,
47
- connection: agent_client_protocol::ConnectionTo<Agent>,
48
- turn: Mutex<TurnState>,
49
- activity: watch::Sender<bool>,
50
- closed: watch::Sender<bool>,
51
- failure: Mutex<Option<NativeError>>,
52
- events: Mutex<Option<mpsc::Sender<SessionEvent>>>,
53
- permissions: Mutex<BTreeMap<String, PendingPermission>>,
54
- configuration: Mutex<SessionConfiguration>,
55
- configuring: tokio::sync::Mutex<()>,
56
- task: Mutex<Option<JoinHandle<()>>>,
57
- }
58
-
59
- #[derive(Default)]
60
- struct TurnState {
61
- reserved: Option<String>,
62
- current: Option<String>,
63
- cancelled: bool,
64
- }
65
-
66
- struct PendingPermission {
67
- request: RequestPermissionRequest,
68
- responder: Responder<RequestPermissionResponse>,
69
- expires: Instant,
70
- }
71
-
72
- struct PromptCommand {
73
- prompt: Prompt,
74
- result: oneshot::Sender<Result<StopReason>>,
75
- }
76
-
77
- struct PromptGuard(Option<(Arc<SessionState>, String)>);
78
-
79
- impl Drop for PromptGuard {
80
- fn drop(&mut self) {
81
- let Some((state, request_id)) = &self.0 else {
82
- return;
83
- };
84
- // Release the turn lock before cleanup takes it again.
85
- let active = lock(&state.turn).reserved.as_ref() == Some(request_id);
86
- if active {
87
- // Abandoning a prompt cannot leave unattended agent work running.
88
- state.close(NativeError::Closed, true);
89
- }
90
- }
91
- }
92
-
93
- impl Drop for SessionLease {
94
- fn drop(&mut self) {
95
- let active = lock(&self.state.turn).reserved.is_some();
96
- self.state.close(NativeError::Closed, active);
97
- }
98
- }
99
-
100
- impl SessionState {
101
- fn is_closed(&self) -> bool {
102
- *self.closed.borrow() || self.client.is_closed()
103
- }
104
-
105
- fn error(&self) -> NativeError {
106
- lock(&self.failure)
107
- .clone()
108
- .unwrap_or_else(|| self.client.error())
109
- }
110
-
111
- fn emit(&self, event: Event) -> Result<()> {
112
- if let Event::Update { update } = &event {
113
- lock(&self.configuration).apply(update);
114
- }
115
- let request_id = lock(&self.turn).current.clone();
116
- let result = lock(&self.events)
117
- .as_ref()
118
- .ok_or(NativeError::Closed)?
119
- .try_send(SessionEvent { request_id, event });
120
- match result {
121
- Ok(()) => Ok(()),
122
- Err(mpsc::error::TrySendError::Full(_)) => {
123
- self.close(NativeError::EventBufferFull, true);
124
- Err(NativeError::EventBufferFull)
125
- }
126
- Err(mpsc::error::TrySendError::Closed(_)) => {
127
- self.close(NativeError::Closed, true);
128
- Err(NativeError::Closed)
129
- }
130
- }
131
- }
132
-
133
- fn deny_permissions(&self) {
134
- for (_, pending) in std::mem::take(&mut *lock(&self.permissions)) {
135
- let _ = pending.responder.respond(RequestPermissionResponse::new(
136
- RequestPermissionOutcome::Cancelled,
137
- ));
138
- }
139
- }
140
-
141
- fn close(&self, error: NativeError, stop_connection: bool) {
142
- if !*self.closed.borrow() {
143
- *lock(&self.failure) = Some(error.clone());
144
- let _ = self
145
- .connection
146
- .send_notification(CancelNotification::new(self.id.clone()));
147
- self.deny_permissions();
148
- let request_id = lock(&self.turn).current.clone();
149
- if let Some(events) = lock(&self.events).take()
150
- && (request_id.is_some() || error != NativeError::Closed)
151
- {
152
- let _ = events.try_send(SessionEvent {
153
- request_id,
154
- event: Event::Error {
155
- code: error.code().into(),
156
- message: error.to_string(),
157
- },
158
- });
159
- }
160
- self.closed.send_replace(true);
161
- self.activity.send_replace(false);
162
- if let Some(task) = lock(&self.task).as_ref() {
163
- task.abort();
164
- }
165
- }
166
- if stop_connection {
167
- self.client.abort();
168
- }
169
- }
170
-
171
- fn finish(&self, outcome: &Result<StopReason>) -> Result<()> {
172
- self.deny_permissions();
173
- let event = match outcome {
174
- Ok(stop_reason) => Event::Completed {
175
- stop_reason: *stop_reason,
176
- },
177
- Err(error) => Event::Error {
178
- code: error.code().into(),
179
- message: error.to_string(),
180
- },
181
- };
182
- self.emit(event)?;
183
- *lock(&self.turn) = TurnState::default();
184
- self.activity.send_replace(false);
185
- Ok(())
186
- }
187
- }
188
-
189
- impl NativeSession {
190
- pub(super) fn start(
191
- client: Arc<ClientLease>,
192
- session: ActiveSession<'static, Agent>,
193
- ) -> Result<Self> {
194
- let (events_tx, events_rx) = mpsc::channel(client.options.event_capacity);
195
- let (commands_tx, commands_rx) = mpsc::channel(1);
196
- let (activity, _) = watch::channel(false);
197
- let (closed, _) = watch::channel(false);
198
- let state = Arc::new(SessionState {
199
- id: session.session_id().clone(),
200
- client: client.state.clone(),
201
- connection: session.connection().clone(),
202
- turn: Mutex::new(TurnState::default()),
203
- activity,
204
- closed,
205
- failure: Mutex::new(None),
206
- events: Mutex::new(Some(events_tx)),
207
- permissions: Mutex::new(BTreeMap::new()),
208
- configuration: Mutex::new(SessionConfiguration {
209
- options: session.config_options().unwrap_or_default().to_vec(),
210
- modes: session.modes().cloned(),
211
- }),
212
- configuring: tokio::sync::Mutex::new(()),
213
- task: Mutex::new(None),
214
- });
215
- let worker_state = state.clone();
216
- let options = client.options.clone();
217
- let task = tokio::spawn(async move {
218
- if let Err(error) =
219
- run_session(session, commands_rx, worker_state.clone(), options).await
220
- {
221
- worker_state.close(error, true);
222
- }
223
- });
224
- *lock(&state.task) = Some(task);
225
- Ok(Self {
226
- handle: SessionHandle {
227
- lease: Arc::new(SessionLease {
228
- state,
229
- commands: commands_tx,
230
- client,
231
- }),
232
- },
233
- events: Some(events_rx),
234
- })
235
- }
236
-
237
- /// Clone the control handle; it can be used while the receiver is polled elsewhere.
238
- pub fn handle(&self) -> SessionHandle {
239
- self.handle.clone()
240
- }
241
-
242
- /// Take the sole stream, including any history queued during session restoration.
243
- pub fn take_events(&mut self) -> Result<mpsc::Receiver<SessionEvent>> {
244
- self.events.take().ok_or(NativeError::EventsTaken)
245
- }
246
- }
247
-
248
- impl SessionHandle {
249
- /// Latest agent-advertised controls, including dependent changes and notifications.
250
- pub fn configuration(&self) -> SessionConfiguration {
251
- lock(&self.lease.state.configuration).clone()
252
- }
253
-
254
- /// Select an exact model advertised by this session, without any fallback.
255
- pub async fn set_model(&self, model: &str) -> Result<SessionConfiguration> {
256
- let id = self
257
- .configuration()
258
- .model_option()
259
- .map(|option| option.id.to_string())
260
- .ok_or(NativeError::Unsupported("model selection"))?;
261
- self.set_config_option(&id, model.into()).await
262
- }
263
-
264
- /// Change an advertised select or boolean control and retain the full response.
265
- /// Unknown controls and values fail before sending a request to the agent.
266
- pub async fn set_config_option(
267
- &self,
268
- id: &str,
269
- value: crate::acp::SessionConfigOptionValue,
270
- ) -> Result<SessionConfiguration> {
271
- let state = &self.lease.state;
272
- let _serial = state.configuring.lock().await;
273
- if state.is_closed() {
274
- return Err(state.error());
275
- }
276
- if !self.configuration().accepts(id, &value) {
277
- return Err(NativeError::Unsupported("the selected configuration value"));
278
- }
279
- let request =
280
- crate::acp::SetSessionConfigOptionRequest::new(state.id.clone(), id.to_owned(), value);
281
- let response = match timeout(
282
- self.lease.client.options.operation_timeout,
283
- state.connection.send_request(request).block_task(),
284
- )
285
- .await
286
- {
287
- Ok(result) => result?,
288
- Err(_) => {
289
- state.close(NativeError::Timeout, true);
290
- return Err(NativeError::Timeout);
291
- }
292
- };
293
- state.emit(Event::Update {
294
- update: crate::acp::SessionUpdate::ConfigOptionUpdate(
295
- crate::acp::ConfigOptionUpdate::new(response.config_options),
296
- ),
297
- })?;
298
- Ok(self.configuration())
299
- }
300
-
301
- /// The agent-owned session identifier, suitable for explicit load or resume.
302
- pub fn id(&self) -> &str {
303
- self.lease.state.id.0.as_ref()
304
- }
305
-
306
- /// Send one prompt and await its terminal result while events stream independently.
307
- ///
308
- /// A concurrent prompt fails with `Busy`. Dropping this future after submission
309
- /// closes the connection, ensuring the abandoned turn cannot keep running.
310
- pub async fn prompt(&self, prompt: Prompt) -> Result<StopReason> {
311
- let state = &self.lease.state;
312
- if state.is_closed() {
313
- return Err(state.error());
314
- }
315
- if prompt.request_id.is_empty() || prompt.content.is_empty() {
316
- return Err(NativeError::InvalidOptions(
317
- "a prompt needs a request id and content",
318
- ));
319
- }
320
- let capabilities = &self
321
- .lease
322
- .client
323
- .info
324
- .agent_capabilities
325
- .prompt_capabilities;
326
- for content in &prompt.content {
327
- match content {
328
- ContentBlock::Text(_) | ContentBlock::ResourceLink(_) => {}
329
- ContentBlock::Image(_) if capabilities.image => {}
330
- ContentBlock::Audio(_) if capabilities.audio => {}
331
- ContentBlock::Resource(_) if capabilities.embedded_context => {}
332
- _ => return Err(NativeError::Unsupported("the requested prompt content")),
333
- }
334
- }
335
- {
336
- let mut turn = lock(&state.turn);
337
- if turn.reserved.is_some() {
338
- return Err(NativeError::Busy);
339
- }
340
- turn.reserved = Some(prompt.request_id.clone());
341
- turn.cancelled = false;
342
- state.activity.send_replace(true);
343
- }
344
- let mut guard = PromptGuard(Some((state.clone(), prompt.request_id.clone())));
345
- let (result_tx, result_rx) = oneshot::channel();
346
- self.lease
347
- .commands
348
- .send(PromptCommand {
349
- prompt,
350
- result: result_tx,
351
- })
352
- .await
353
- .map_err(|_| state.error())?;
354
- let mut closed = state.closed.subscribe();
355
- let mut connection_closed = state.client.closed.subscribe();
356
- let result = timeout(self.lease.client.options.prompt_timeout, async {
357
- if state.is_closed() {
358
- return Err(state.error());
359
- }
360
- tokio::select! {
361
- result = result_rx => result.unwrap_or_else(|_| Err(state.error())),
362
- _ = closed.changed() => Err(state.error()),
363
- _ = connection_closed.changed() => Err(state.error()),
364
- }
365
- })
366
- .await;
367
- match result {
368
- Ok(outcome) => {
369
- guard.0 = None;
370
- outcome
371
- }
372
- Err(_) => {
373
- state.close(NativeError::Timeout, true);
374
- guard.0 = None;
375
- Err(NativeError::Timeout)
376
- }
377
- }
378
- }
379
-
380
- /// Request cancellation and wait a bounded time for the active turn to finish.
381
- ///
382
- /// If the agent ignores cancellation, the SDK connection is closed. This also
383
- /// closes other sessions sharing that agent process.
384
- pub async fn cancel(&self) -> Result<()> {
385
- let state = &self.lease.state;
386
- if state.is_closed() {
387
- return Err(state.error());
388
- }
389
- {
390
- let mut turn = lock(&state.turn);
391
- if turn.reserved.is_none() {
392
- return Ok(());
393
- }
394
- turn.cancelled = true;
395
- }
396
- state.deny_permissions();
397
- state
398
- .connection
399
- .send_notification(CancelNotification::new(state.id.clone()))?;
400
- let mut activity = state.activity.subscribe();
401
- if timeout(self.lease.client.options.shutdown_timeout, async {
402
- while *activity.borrow_and_update() {
403
- if activity.changed().await.is_err() {
404
- break;
405
- }
406
- }
407
- })
408
- .await
409
- .is_err()
410
- {
411
- state.close(NativeError::Timeout, true);
412
- return Err(NativeError::Timeout);
413
- }
414
- if state.is_closed() {
415
- Err(state.error())
416
- } else {
417
- Ok(())
418
- }
419
- }
420
-
421
- /// Answer one pending permission request using an option the agent offered.
422
- ///
423
- /// Invalid selections leave the request pending so the application can correct
424
- /// its response. Expired or previously answered requests fail explicitly.
425
- pub async fn respond_permission(
426
- &self,
427
- request_id: &str,
428
- decision: PermissionDecision,
429
- ) -> Result<()> {
430
- let state = &self.lease.state;
431
- if state.is_closed() {
432
- return Err(state.error());
433
- }
434
- let pending = {
435
- let mut permissions = lock(&state.permissions);
436
- let pending = permissions
437
- .get(request_id)
438
- .ok_or(NativeError::UnknownPermission)?;
439
- if pending.expires <= Instant::now() || pending.responder.cancellation().is_cancelled()
440
- {
441
- return Err(NativeError::UnknownPermission);
442
- }
443
- match &decision {
444
- RequestPermissionOutcome::Cancelled => {}
445
- RequestPermissionOutcome::Selected(selected)
446
- if pending
447
- .request
448
- .options
449
- .iter()
450
- .any(|option| option.option_id == selected.option_id) => {}
451
- _ => return Err(NativeError::InvalidPermissionOption),
452
- }
453
- permissions
454
- .remove(request_id)
455
- .ok_or(NativeError::UnknownPermission)?
456
- };
457
- pending
458
- .responder
459
- .respond(RequestPermissionResponse::new(decision))?;
460
- Ok(())
461
- }
462
-
463
- /// Cancel work, detach local routing, and close the remote session when supported.
464
- ///
465
- /// Without `session/close`, persisted agent history remains available for an
466
- /// explicit future load; this method never claims to delete remote history.
467
- pub async fn close(&self) -> Result<()> {
468
- let state = &self.lease.state;
469
- if state.is_closed() {
470
- return Ok(());
471
- }
472
- self.cancel().await?;
473
- if self
474
- .lease
475
- .client
476
- .info
477
- .agent_capabilities
478
- .session_capabilities
479
- .close
480
- .is_some()
481
- {
482
- let response = timeout(
483
- self.lease.client.options.shutdown_timeout,
484
- state
485
- .connection
486
- .send_request(CloseSessionRequest::new(state.id.clone()))
487
- .block_task(),
488
- )
489
- .await;
490
- match response {
491
- Ok(Ok(_)) => {}
492
- Ok(Err(error)) => {
493
- state.close(error.clone().into(), false);
494
- return Err(error.into());
495
- }
496
- Err(_) => {
497
- state.close(NativeError::Timeout, true);
498
- return Err(NativeError::Timeout);
499
- }
500
- }
501
- }
502
- state.close(NativeError::Closed, false);
503
- Ok(())
504
- }
505
- }
506
-
507
- async fn run_session(
508
- mut session: ActiveSession<'static, Agent>,
509
- mut commands: mpsc::Receiver<PromptCommand>,
510
- state: Arc<SessionState>,
511
- options: super::NativeOptions,
512
- ) -> Result<()> {
513
- let (completion_tx, mut completion_rx) = mpsc::unbounded_channel::<Result<StopReason>>();
514
- let mut active: Option<oneshot::Sender<Result<StopReason>>> = None;
515
- let mut closed = state.closed.subscribe();
516
- let mut connection_closed = state.client.closed.subscribe();
517
- let mut expiry = interval(
518
- options
519
- .permission_timeout
520
- .min(std::time::Duration::from_secs(1)),
521
- );
522
- loop {
523
- if state.is_closed() {
524
- return Err(state.error());
525
- }
526
- tokio::select! {
527
- biased;
528
- _ = closed.changed() => return Ok(()),
529
- _ = connection_closed.changed() => return Err(state.client.error()),
530
- message = session.read_update() => {
531
- match message? {
532
- SessionMessage::SessionMessage(dispatch) => {
533
- MatchDispatch::new(dispatch)
534
- .if_notification(async |notification: SessionNotification| {
535
- state.emit(Event::Update { update: notification.update })
536
- .map_err(|_| agent_client_protocol::Error::internal_error())
537
- }).await
538
- .if_request(async |request: RequestPermissionRequest, responder| {
539
- if options.permissions == PermissionPolicy::Deny
540
- || lock(&state.turn).cancelled
541
- || lock(&state.permissions).len() >= options.event_capacity
542
- {
543
- return responder.respond(RequestPermissionResponse::new(RequestPermissionOutcome::Cancelled));
544
- }
545
- let request_id = format!("permission-{}", NEXT_PERMISSION.fetch_add(1, Ordering::Relaxed));
546
- lock(&state.permissions).insert(request_id.clone(), PendingPermission {
547
- request: request.clone(), responder,
548
- expires: Instant::now() + options.permission_timeout,
549
- });
550
- state.emit(Event::Permission { request_id, request })
551
- .map_err(|_| agent_client_protocol::Error::internal_error())
552
- }).await
553
- .otherwise(async |dispatch| {
554
- match dispatch {
555
- Dispatch::Request(_, responder) => responder.respond_with_result(Err(agent_client_protocol::Error::method_not_found())),
556
- _ => Ok(()),
557
- }
558
- }).await?;
559
- }
560
- SessionMessage::StopReason(stop_reason) => {
561
- let _ = completion_tx.send(Ok(stop_reason));
562
- }
563
- _ => return Err(NativeError::Unsupported("the received SDK session event")),
564
- }
565
- }
566
- Some(outcome) = completion_rx.recv(), if active.is_some() => {
567
- state.finish(&outcome)?;
568
- if let Some(result) = active.take() { let _ = result.send(outcome); }
569
- }
570
- Some(command) = commands.recv(), if active.is_none() => {
571
- {
572
- let mut turn = lock(&state.turn);
573
- turn.current = Some(command.prompt.request_id.clone());
574
- }
575
- if lock(&state.turn).cancelled || command.result.is_closed() {
576
- let outcome = Ok(StopReason::Cancelled);
577
- state.finish(&outcome)?;
578
- let _ = command.result.send(outcome);
579
- continue;
580
- }
581
- active = Some(command.result);
582
- let tx = completion_tx.clone();
583
- session.connection().send_request(PromptRequest::new(state.id.clone(), command.prompt.content))
584
- .on_receiving_result(async move |result: std::result::Result<PromptResponse, agent_client_protocol::Error>| {
585
- // Earlier notifications are already on ActiveSession's queue.
586
- // The biased reader drains them before publishing completion.
587
- let _ = tx.send(result.map(|response| response.stop_reason).map_err(NativeError::from));
588
- Ok(())
589
- })?;
590
- }
591
- _ = expiry.tick() => {
592
- let expired: Vec<_> = lock(&state.permissions).iter()
593
- .filter(|(_, pending)| pending.expires <= Instant::now() || pending.responder.cancellation().is_cancelled())
594
- .map(|(id, _)| id.clone()).collect();
595
- for id in expired {
596
- if let Some(pending) = lock(&state.permissions).remove(&id) {
597
- let _ = pending.responder.respond(RequestPermissionResponse::new(RequestPermissionOutcome::Cancelled));
598
- }
599
- }
600
- }
601
- }
602
- }
603
- }