@alwith/module-chat 0.5.19 → 0.5.21

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 (483) hide show
  1. package/README.md +240 -1
  2. package/THIRD_PARTY_NOTICES.md +13 -0
  3. package/assets/catalogs/alwith/models.json +72 -0
  4. package/assets/catalogs/custom/models.json +604 -0
  5. package/assets/catalogs/custom/sources.json +168 -0
  6. package/assets/catalogs/deepseek/models.json +139 -0
  7. package/assets/catalogs/openrouter/models.json +231 -0
  8. package/assets/catalogs/qwen/models.json +253 -0
  9. package/assets/catalogs/xai/models.json +129 -0
  10. package/assets/provider-catalog.json +127 -0
  11. package/dist/activity-host.js +1 -1
  12. package/dist/approval/choice-elicitation-form.js +1 -1
  13. package/dist/approval/choice-schema.js +1 -1
  14. package/dist/approval/permission-options.js +1 -1
  15. package/dist/approval/permission-view.js +1 -1
  16. package/dist/approval/schema-elicitation-form.js +1 -1
  17. package/dist/approval/url-elicitation-card.js +1 -1
  18. package/dist/chunk-00eytt1z.js +2 -0
  19. package/dist/chunk-0fs2k5fe.js +1289 -0
  20. package/dist/chunk-0gersbj0.js +2 -0
  21. package/dist/chunk-0gy6ngda.js +2 -0
  22. package/dist/chunk-0mp7tyea.js +2 -0
  23. package/dist/chunk-0vhkv9ax.js +2 -0
  24. package/dist/{chunk-b53ky6rb.js → chunk-141kppzb.js} +2 -2
  25. package/dist/chunk-14exd146.js +2 -0
  26. package/dist/{chunk-yjtq166b.js → chunk-156m3888.js} +3 -3
  27. package/dist/{chunk-jx1cngyb.js → chunk-1e6x0018.js} +2 -2
  28. package/dist/{chunk-01rfnabj.js → chunk-1f628zap.js} +2 -2
  29. package/dist/{chunk-h3antqdd.js → chunk-1ppfn0e1.js} +2 -2
  30. package/dist/chunk-1q2cykp4.js +2 -0
  31. package/dist/chunk-1tkzxktd.js +2 -0
  32. package/dist/{chunk-9ej4c7a8.js → chunk-23rjsm3a.js} +2 -2
  33. package/dist/chunk-2ce8gd89.js +2 -0
  34. package/dist/chunk-2f1qx13s.js +2 -0
  35. package/dist/{chunk-0vy6cqmw.js → chunk-2nvsvw67.js} +2 -2
  36. package/dist/chunk-2tce3pc5.js +3 -0
  37. package/dist/chunk-2tkeevm0.js +2 -0
  38. package/dist/chunk-33620ca6.js +2 -0
  39. package/dist/chunk-3aq5c12k.js +2 -0
  40. package/dist/{chunk-jt8h82c2.js → chunk-3jcmv5qf.js} +2 -2
  41. package/dist/chunk-3n47hknp.js +2 -0
  42. package/dist/chunk-3nr5qe41.js +2 -0
  43. package/dist/chunk-3yvd77ph.js +2 -0
  44. package/dist/chunk-40bcp4pa.js +2 -0
  45. package/dist/{chunk-9xkp5x7h.js → chunk-42hkbpey.js} +2 -2
  46. package/dist/chunk-42nhwnbe.js +4 -0
  47. package/dist/chunk-4s6gx750.js +2 -0
  48. package/dist/chunk-4w3g7d6w.js +2 -0
  49. package/dist/chunk-52p7kyam.js +2 -0
  50. package/dist/{chunk-kvx8fv1e.js → chunk-59957gfy.js} +2 -2
  51. package/dist/chunk-59exzf5n.js +2 -0
  52. package/dist/chunk-5cdr7q6f.js +4 -0
  53. package/dist/chunk-5nc3dtyt.js +2 -0
  54. package/dist/chunk-63kxepkh.js +2 -0
  55. package/dist/chunk-67hrx4kg.js +2 -0
  56. package/dist/{chunk-eeq8d3x7.js → chunk-6dn3j8a2.js} +2 -2
  57. package/dist/{chunk-cdrmg9jj.js → chunk-72x7rae0.js} +2 -2
  58. package/dist/chunk-77j8n5k5.js +2 -0
  59. package/dist/{chunk-d6c0mnth.js → chunk-78s6h7r4.js} +2 -2
  60. package/dist/chunk-7p1r1ha9.js +2 -0
  61. package/dist/{chunk-hwh88n0v.js → chunk-7wk3d01c.js} +4 -4
  62. package/dist/chunk-80ckz04b.js +2 -0
  63. package/dist/chunk-82xjggwn.js +2 -0
  64. package/dist/chunk-85ffkcch.js +2 -0
  65. package/dist/chunk-8c042xya.js +2 -0
  66. package/dist/{chunk-09r35ts9.js → chunk-8ch9444t.js} +2 -2
  67. package/dist/{chunk-2hk04fh3.js → chunk-8hte6dh7.js} +2 -2
  68. package/dist/{chunk-dj4e0q7k.js → chunk-8jxcdap5.js} +2 -2
  69. package/dist/chunk-8qw8erv6.js +2 -0
  70. package/dist/chunk-8t36vprh.js +2 -0
  71. package/dist/{chunk-a9s3m9fs.js → chunk-8w22ck92.js} +2 -2
  72. package/dist/chunk-908ndb9r.js +2 -0
  73. package/dist/chunk-983gkw32.js +2 -0
  74. package/dist/chunk-9g67z1b4.js +2 -0
  75. package/dist/chunk-9mky3b7v.js +2 -0
  76. package/dist/chunk-9n79tr1q.js +2 -0
  77. package/dist/{chunk-ekd97p2x.js → chunk-9sq2etjk.js} +2 -2
  78. package/dist/chunk-a8p82wp7.js +2 -0
  79. package/dist/chunk-ajpxjj5m.js +2 -0
  80. package/dist/chunk-ap0vmczf.js +2 -0
  81. package/dist/chunk-aqvy57zs.js +2 -0
  82. package/dist/{chunk-9ebnn34t.js → chunk-aza82m2p.js} +2 -2
  83. package/dist/chunk-b2wczqtd.js +2 -0
  84. package/dist/chunk-b3jg6nzv.js +3 -0
  85. package/dist/{chunk-qy2prx7m.js → chunk-b614gnnv.js} +2 -2
  86. package/dist/{chunk-50mckd2p.js → chunk-c1b8z8pa.js} +2 -2
  87. package/dist/chunk-c38t8809.js +2 -0
  88. package/dist/chunk-c9nbavk0.js +2 -0
  89. package/dist/chunk-cbwya2ss.js +2 -0
  90. package/dist/chunk-cg8ekwka.js +2 -0
  91. package/dist/chunk-dv65h7z5.js +2 -0
  92. package/dist/chunk-dya74vts.js +2 -0
  93. package/dist/chunk-dyqvhn6y.js +5 -0
  94. package/dist/chunk-dyrgfdxz.js +2 -0
  95. package/dist/chunk-e9ntencj.js +2 -0
  96. package/dist/{chunk-e92r4g3v.js → chunk-ec9rgnt3.js} +2 -2
  97. package/dist/chunk-efrn25h9.js +2 -0
  98. package/dist/chunk-emcefs0g.js +2 -0
  99. package/dist/chunk-et8rcxw6.js +2 -0
  100. package/dist/chunk-f28hhbf4.js +2 -0
  101. package/dist/chunk-f3924gdb.js +2 -0
  102. package/dist/chunk-f8zy35gz.js +2 -0
  103. package/dist/chunk-f98at4r5.js +2 -0
  104. package/dist/chunk-fke98cj0.js +2 -0
  105. package/dist/chunk-g242n3dt.js +2 -0
  106. package/dist/{chunk-q4q4f03j.js → chunk-g73f62qm.js} +2 -2
  107. package/dist/{chunk-k9mbpf0g.js → chunk-h1bhhqtq.js} +2 -2
  108. package/dist/chunk-h5m2fpp4.js +2 -0
  109. package/dist/chunk-hv1ejvhg.js +2 -0
  110. package/dist/chunk-j86x2rn0.js +2 -0
  111. package/dist/chunk-jm6zja6h.js +2 -0
  112. package/dist/{chunk-z5tstgsh.js → chunk-k5rkpqbh.js} +2 -2
  113. package/dist/chunk-k5wgf59a.js +2 -0
  114. package/dist/{chunk-4xhvh2dn.js → chunk-k7k6qsqh.js} +2 -2
  115. package/dist/chunk-kc5k5e59.js +3 -0
  116. package/dist/chunk-kvc6ewkt.js +4 -0
  117. package/dist/chunk-kxmajv0m.js +3 -0
  118. package/dist/{chunk-m2hpfdch.js → chunk-m2b8kzpk.js} +2 -2
  119. package/dist/{chunk-e44hny11.js → chunk-m7wn4z9x.js} +2 -2
  120. package/dist/chunk-mcjwwxa1.js +2 -0
  121. package/dist/chunk-memvzzc6.js +2 -0
  122. package/dist/{chunk-fgzq0ktw.js → chunk-mg2mkzkk.js} +2 -2
  123. package/dist/{chunk-0zp04d1m.js → chunk-mgm1x3de.js} +2 -2
  124. package/dist/chunk-mwpchd85.js +3 -0
  125. package/dist/chunk-myrdfa3s.js +2 -0
  126. package/dist/chunk-n0khj68q.js +2 -0
  127. package/dist/{chunk-c2h76vnt.js → chunk-n929wkw7.js} +2 -2
  128. package/dist/chunk-nacjea1s.js +2 -0
  129. package/dist/{chunk-gcx4fk1a.js → chunk-nn25kjm4.js} +2 -2
  130. package/dist/{chunk-f8wzz84b.js → chunk-nq7gg9vg.js} +2 -2
  131. package/dist/{chunk-a4wrn6ep.js → chunk-nqw4deag.js} +2 -2
  132. package/dist/{chunk-gr1nnczz.js → chunk-ns5rnxdj.js} +2 -2
  133. package/dist/{chunk-6p41wmgs.js → chunk-nxp1b8ny.js} +2 -2
  134. package/dist/chunk-p4bb313p.js +3 -0
  135. package/dist/chunk-py837qjk.js +1 -0
  136. package/dist/chunk-q7nn5xe5.js +2 -0
  137. package/dist/chunk-qjhkzdhm.js +2 -0
  138. package/dist/{chunk-eyf9bxyx.js → chunk-qwfwxfhn.js} +2 -2
  139. package/dist/chunk-qxcnyvps.js +2 -0
  140. package/dist/chunk-r3qrftds.js +2 -0
  141. package/dist/chunk-r9dt4bs3.js +2 -0
  142. package/dist/chunk-rbqn4725.js +2 -0
  143. package/dist/chunk-rcbb4ke2.js +2 -0
  144. package/dist/chunk-rekc1q3m.js +2 -0
  145. package/dist/chunk-rwkkqdcv.js +2 -0
  146. package/dist/{chunk-fcy4sv9f.js → chunk-rwnz06kr.js} +2 -2
  147. package/dist/{chunk-5n4mefej.js → chunk-s55n9cby.js} +2 -2
  148. package/dist/chunk-sxh0pd3y.js +2 -0
  149. package/dist/chunk-sy5tq3y6.js +2 -0
  150. package/dist/chunk-t0cr21e3.js +2 -0
  151. package/dist/chunk-t97yjy4f.js +2 -0
  152. package/dist/chunk-v4t0p6pp.js +2 -0
  153. package/dist/{chunk-rsfwc38x.js → chunk-vcy5vyp7.js} +3 -3
  154. package/dist/chunk-vkrgdqnm.js +2 -0
  155. package/dist/chunk-vs02ry2r.js +2 -0
  156. package/dist/chunk-vyk4zh1m.js +7 -0
  157. package/dist/{chunk-5nj2fjej.js → chunk-w0hpztj7.js} +2 -2
  158. package/dist/chunk-w6rwngm3.js +2 -0
  159. package/dist/{chunk-jc52024g.js → chunk-w9dh298r.js} +2 -2
  160. package/dist/chunk-wvdncbrt.js +2 -0
  161. package/dist/chunk-x2yc5748.js +2 -0
  162. package/dist/chunk-x334e7wb.js +3 -0
  163. package/dist/{chunk-qmc18ejg.js → chunk-x6nz6eyb.js} +2 -2
  164. package/dist/chunk-xdm2are3.js +2 -0
  165. package/dist/{chunk-0zph0gwq.js → chunk-xf36kt74.js} +3 -3
  166. package/dist/{chunk-tzyc5myt.js → chunk-xgjkj9j8.js} +2 -2
  167. package/dist/chunk-xktybk48.js +2 -0
  168. package/dist/{chunk-210b2kk6.js → chunk-xmstt6hh.js} +2 -2
  169. package/dist/chunk-xrs7x5ah.js +2 -0
  170. package/dist/chunk-xyvqcpjx.js +2 -0
  171. package/dist/chunk-y7xcync7.js +2 -0
  172. package/dist/chunk-ye9tsdhn.js +2 -0
  173. package/dist/{chunk-5e10bzg2.js → chunk-z2fjwkmt.js} +2 -2
  174. package/dist/{chunk-nkqe2e8s.js → chunk-z2v008kc.js} +2 -2
  175. package/dist/chunk-z71pp1mb.js +4 -0
  176. package/dist/chunk-zxkvvecz.js +2 -0
  177. package/dist/codex/activity-group.js +1 -1
  178. package/dist/codex/assistant-message.js +1 -1
  179. package/dist/codex/async-question-card.js +1 -1
  180. package/dist/codex/disclosure-state.js +1 -1
  181. package/dist/codex/edited-files-card.js +1 -1
  182. package/dist/codex/image-view-activity.js +1 -1
  183. package/dist/codex/markdown-renderer.js +1 -1
  184. package/dist/codex/navigation-audio.js +1 -1
  185. package/dist/codex/navigation-preview.js +1 -1
  186. package/dist/codex/navigation-rail.js +1 -1
  187. package/dist/codex/patch-view.js +1 -1
  188. package/dist/codex/plan.js +1 -1
  189. package/dist/codex/timeline-virtualizer.js +1 -1
  190. package/dist/codex/turn-activity.js +1 -1
  191. package/dist/codex/user-message.js +1 -1
  192. package/dist/codex/virtualized-turn-list.js +1 -1
  193. package/dist/collections/collection-emoji.d.ts +4 -0
  194. package/dist/collections/collection-emoji.js +1 -0
  195. package/dist/collections/collection-menu.d.ts +15 -0
  196. package/dist/collections/collection-menu.js +1 -0
  197. package/dist/collections/collection-panel.d.ts +11 -0
  198. package/dist/collections/collection-panel.js +1 -0
  199. package/dist/collections/collections.d.ts +6 -0
  200. package/dist/collections/collections.js +1 -0
  201. package/dist/collections/host.d.ts +19 -0
  202. package/dist/collections/host.js +1 -0
  203. package/dist/collections/locales.d.ts +71 -0
  204. package/dist/collections/locales.js +1 -0
  205. package/dist/collections/model.d.ts +95 -0
  206. package/dist/collections/model.js +1 -0
  207. package/dist/collections/store.d.ts +30 -0
  208. package/dist/collections/store.js +1 -0
  209. package/dist/composer/completion-filter.js +1 -1
  210. package/dist/composer/completion-menu.js +1 -1
  211. package/dist/composer/completion-trigger.js +1 -1
  212. package/dist/composer/effort-slider.js +1 -1
  213. package/dist/composer/menu-radio.js +1 -1
  214. package/dist/composer/model-select.js +1 -1
  215. package/dist/composer/permission-mode-select.js +1 -1
  216. package/dist/composer/prompt-input-attachments.js +1 -1
  217. package/dist/composer/prompt-input-clipboard.js +1 -1
  218. package/dist/composer/prompt-input-context.js +1 -1
  219. package/dist/composer/prompt-input-textarea.js +1 -1
  220. package/dist/composer/prompt-input.js +1 -1
  221. package/dist/conversation/action-card.js +1 -1
  222. package/dist/conversation/composer/composer.js +1 -1
  223. package/dist/conversation/composer/config-options.js +1 -1
  224. package/dist/conversation/composer/context.js +1 -1
  225. package/dist/conversation/composer/drafts.js +1 -1
  226. package/dist/conversation/composer/file-items.js +1 -1
  227. package/dist/conversation/composer/long-text.js +1 -1
  228. package/dist/conversation/composer/mention-chips.js +1 -1
  229. package/dist/conversation/composer/mention-uri.js +1 -1
  230. package/dist/conversation/composer/model-menu.js +1 -1
  231. package/dist/conversation/composer/pasted-text-attachment.js +1 -1
  232. package/dist/conversation/composer/permission-mode-menu.js +1 -1
  233. package/dist/conversation/composer/prediction.js +1 -1
  234. package/dist/conversation/composer/slash-command-button.js +1 -1
  235. package/dist/conversation/composer/submit-button.js +1 -1
  236. package/dist/conversation/composer/usage-meter.js +1 -1
  237. package/dist/conversation/connection-notice.d.ts +8 -0
  238. package/dist/conversation/connection-notice.js +1 -0
  239. package/dist/conversation/context.js +1 -1
  240. package/dist/conversation/conversation-body.js +1 -1
  241. package/dist/conversation/conversation-search.d.ts +8 -0
  242. package/dist/conversation/conversation-search.js +1 -0
  243. package/dist/conversation/conversation-view.d.ts +1 -0
  244. package/dist/conversation/conversation-view.js +1 -1
  245. package/dist/conversation/conversation.d.ts +3 -0
  246. package/dist/conversation/conversation.js +1 -1
  247. package/dist/conversation/diff-modal.js +1 -1
  248. package/dist/conversation/draft-project-picker.d.ts +7 -0
  249. package/dist/conversation/draft-project-picker.js +1 -0
  250. package/dist/conversation/session-actions.js +1 -1
  251. package/dist/conversation/subagent-sessions.js +1 -1
  252. package/dist/conversation/types.d.ts +6 -1
  253. package/dist/image-lightbox.js +1 -1
  254. package/dist/image-preview-dialog.js +1 -1
  255. package/dist/lib/code-highlighter.js +1 -1
  256. package/dist/lib/fuzzy.js +1 -1
  257. package/dist/lib/group-blocks.js +1 -1
  258. package/dist/lib/image-encode.js +1 -1
  259. package/dist/lib/limits.js +1 -1
  260. package/dist/lib/markdown-parser.js +1 -1
  261. package/dist/lib/markdown-rules.js +1 -1
  262. package/dist/lib/model-name.js +1 -1
  263. package/dist/lib/pointer-centered-zoom.js +1 -1
  264. package/dist/lib/prepare-prompt-files.js +1 -1
  265. package/dist/lib/stream-style.js +1 -1
  266. package/dist/lib/streaming-markdown.js +1 -1
  267. package/dist/locales.d.ts +1914 -0
  268. package/dist/locales.js +1 -1
  269. package/dist/plugins/catalog-header.d.ts +6 -0
  270. package/dist/plugins/catalog-header.js +1 -0
  271. package/dist/plugins/catalog-skeleton.d.ts +3 -0
  272. package/dist/plugins/catalog-skeleton.js +1 -0
  273. package/dist/plugins/host.d.ts +49 -0
  274. package/dist/plugins/host.js +1 -0
  275. package/dist/plugins/locales.d.ts +1136 -0
  276. package/dist/plugins/locales.js +1 -0
  277. package/dist/plugins/new-chat-directory.d.ts +2 -0
  278. package/dist/plugins/new-chat-directory.js +1 -0
  279. package/dist/plugins/pane.d.ts +12 -0
  280. package/dist/plugins/pane.js +1 -0
  281. package/dist/plugins/panel-item.d.ts +8 -0
  282. package/dist/plugins/panel-item.js +1 -0
  283. package/dist/plugins/plugin-detail-page.d.ts +5 -0
  284. package/dist/plugins/plugin-detail-page.js +1 -0
  285. package/dist/plugins/plugin-icon.d.ts +7 -0
  286. package/dist/plugins/plugin-icon.js +1 -0
  287. package/dist/plugins/plugin-icons.d.ts +1 -0
  288. package/dist/plugins/plugin-icons.js +1 -0
  289. package/dist/plugins/plugins-page.d.ts +12 -0
  290. package/dist/plugins/plugins-page.js +1 -0
  291. package/dist/plugins/plugins.css +199 -0
  292. package/dist/plugins/plugins.d.ts +14 -0
  293. package/dist/plugins/plugins.js +1 -0
  294. package/dist/plugins/read-skill-document.d.ts +2 -0
  295. package/dist/plugins/read-skill-document.js +1 -0
  296. package/dist/plugins/skill-document.d.ts +7 -0
  297. package/dist/plugins/skill-document.js +1 -0
  298. package/dist/plugins/skills-tab.d.ts +6 -0
  299. package/dist/plugins/skills-tab.js +1 -0
  300. package/dist/plugins/store.d.ts +62 -0
  301. package/dist/plugins/store.js +1 -0
  302. package/dist/plugins/toolbox-layout.d.ts +7 -0
  303. package/dist/plugins/toolbox-layout.js +1 -0
  304. package/dist/search/chat-search.css +9 -0
  305. package/dist/search/chat-search.d.ts +1 -0
  306. package/dist/search/chat-search.js +1 -1
  307. package/dist/search/codex-source-matches.d.ts +4 -0
  308. package/dist/search/codex-source-matches.js +1 -0
  309. package/dist/search/dom-matches.js +1 -1
  310. package/dist/search/find-bar.js +1 -1
  311. package/dist/search/literal-matches.js +1 -1
  312. package/dist/session-list/account-menu.d.ts +26 -0
  313. package/dist/session-list/account-menu.js +1 -0
  314. package/dist/session-list/activity-list.d.ts +11 -0
  315. package/dist/session-list/activity-list.js +1 -0
  316. package/dist/session-list/archived-sessions.js +1 -1
  317. package/dist/session-list/help-menu.d.ts +5 -0
  318. package/dist/session-list/help-menu.js +1 -0
  319. package/dist/session-list/highlight.js +1 -1
  320. package/dist/session-list/host.d.ts +2 -0
  321. package/dist/session-list/host.js +1 -1
  322. package/dist/session-list/hover-info-card.js +1 -1
  323. package/dist/session-list/locales.d.ts +91 -0
  324. package/dist/session-list/locales.js +1 -1
  325. package/dist/session-list/navigation-header.d.ts +14 -0
  326. package/dist/session-list/navigation-header.js +1 -0
  327. package/dist/session-list/navigation-store.d.ts +19 -0
  328. package/dist/session-list/navigation-store.js +1 -0
  329. package/dist/session-list/navigation-tabs.d.ts +20 -0
  330. package/dist/session-list/navigation-tabs.js +1 -0
  331. package/dist/session-list/navigation.js +1 -1
  332. package/dist/session-list/overflow-marquee.js +1 -1
  333. package/dist/session-list/platform.d.ts +2 -0
  334. package/dist/session-list/platform.js +1 -0
  335. package/dist/session-list/row-stop-button.js +1 -1
  336. package/dist/session-list/session-groups.js +1 -1
  337. package/dist/session-list/session-info-card.js +1 -1
  338. package/dist/session-list/session-list.d.ts +10 -0
  339. package/dist/session-list/session-list.js +1 -1
  340. package/dist/session-list/session-row.js +1 -1
  341. package/dist/session-list/session-state-dot.js +1 -1
  342. package/dist/session-list/session-state-menu.js +1 -1
  343. package/dist/session-list/shortcut-hint.d.ts +14 -0
  344. package/dist/session-list/shortcut-hint.js +1 -0
  345. package/dist/session-list/shortcut.d.ts +2 -0
  346. package/dist/session-list/shortcut.js +1 -0
  347. package/dist/session-list/sidebar-overlay.js +1 -1
  348. package/dist/session-list/trailing-swap.js +1 -1
  349. package/dist/session-list/use-activity-notification.d.ts +1 -0
  350. package/dist/session-list/use-activity-notification.js +1 -0
  351. package/dist/session-list/use-activity-preview.js +1 -1
  352. package/dist/session-list/use-cmd-held.d.ts +1 -0
  353. package/dist/session-list/use-cmd-held.js +1 -0
  354. package/dist/session-list/use-project-sessions.js +1 -1
  355. package/dist/session-list/virtual-session-rows.js +1 -1
  356. package/dist/session-timeline/activity-group.js +1 -1
  357. package/dist/session-timeline/activity-projection.js +1 -1
  358. package/dist/session-timeline/assistant-content.js +1 -1
  359. package/dist/session-timeline/assistant-turn.js +1 -1
  360. package/dist/session-timeline/async-questions.js +1 -1
  361. package/dist/session-timeline/edited-files-card.js +1 -1
  362. package/dist/session-timeline/history-timeline.js +1 -1
  363. package/dist/session-timeline/host.js +1 -1
  364. package/dist/session-timeline/navigation-rail.js +1 -1
  365. package/dist/session-timeline/plan.js +1 -1
  366. package/dist/session-timeline/question-reply.js +1 -1
  367. package/dist/session-timeline/resource-content.js +1 -1
  368. package/dist/session-timeline/session-timeline.js +1 -1
  369. package/dist/session-timeline/timeline-registry.js +1 -1
  370. package/dist/session-timeline/turn-activity.js +1 -1
  371. package/dist/session-timeline/turn-error.js +1 -1
  372. package/dist/session-timeline/turn-retry.js +1 -1
  373. package/dist/session-timeline/turn-time.js +1 -1
  374. package/dist/session-timeline/turns.js +1 -1
  375. package/dist/session-timeline/use-timeline-scroll.js +1 -1
  376. package/dist/session-timeline/user-message.js +1 -1
  377. package/dist/settings/codex-account-card.d.ts +18 -0
  378. package/dist/settings/codex-account-card.js +1 -0
  379. package/dist/settings/login-card.d.ts +6 -0
  380. package/dist/settings/login-card.js +1 -0
  381. package/dist/settings/model-alias-settings.d.ts +6 -0
  382. package/dist/settings/model-alias-settings.js +1 -0
  383. package/dist/settings/model-aliases.d.ts +17 -0
  384. package/dist/settings/model-aliases.js +1 -0
  385. package/dist/settings/provider-logos.d.ts +5 -0
  386. package/dist/settings/provider-logos.js +1 -0
  387. package/dist/settings/provider-section.d.ts +52 -0
  388. package/dist/settings/provider-section.js +1 -0
  389. package/dist/settings/providers-port.d.ts +32 -0
  390. package/dist/settings/providers-port.js +1 -0
  391. package/dist/settings/providers.d.ts +92 -0
  392. package/dist/settings/providers.js +1 -0
  393. package/dist/settings/settings-bridge.d.ts +39 -0
  394. package/dist/settings/settings-bridge.js +1 -0
  395. package/dist/settings/settings.d.ts +9 -0
  396. package/dist/settings/settings.js +1 -0
  397. package/dist/stage.d.ts +1 -0
  398. package/dist/stage.js +1 -1
  399. package/emojibase/LICENSE +21 -0
  400. package/emojibase/en/data.json +51183 -0
  401. package/emojibase/en/messages.json +124 -0
  402. package/emojibase/zh/data.json +48992 -0
  403. package/emojibase/zh/messages.json +124 -0
  404. package/licenses/_dnd-kit_core-LICENSE +21 -0
  405. package/licenses/_dnd-kit_sortable-LICENSE +21 -0
  406. package/licenses/_dnd-kit_utilities-LICENSE +21 -0
  407. package/licenses/_solar-icons_react-LICENSE +11 -0
  408. package/licenses/_solar-icons_react-LICENSE-THIRD-PARTY +14 -0
  409. package/licenses/frimousse-LICENSE +21 -0
  410. package/package.json +36 -4
  411. package/rust/Cargo.lock +3844 -0
  412. package/rust/Cargo.toml +29 -0
  413. package/rust/build.rs +16 -0
  414. package/rust/permissions/autogenerated/reference.md +296 -0
  415. package/rust/permissions/default.toml +20 -0
  416. package/rust/permissions/schemas/schema.json +292 -0
  417. package/rust/src/lib.rs +79 -0
  418. package/rust/src/providers/managed.rs +801 -0
  419. package/rust/src/providers/tests.rs +681 -0
  420. package/rust/src/providers.rs +984 -0
  421. package/rust/src/skills.rs +130 -0
  422. package/dist/chunk-04mj5ftg.js +0 -7
  423. package/dist/chunk-0jvfabsq.js +0 -2
  424. package/dist/chunk-107y8e8x.js +0 -2
  425. package/dist/chunk-22h5rh2h.js +0 -2
  426. package/dist/chunk-31yt34hy.js +0 -2
  427. package/dist/chunk-3hp5t5wf.js +0 -2
  428. package/dist/chunk-3jcx1ns0.js +0 -2
  429. package/dist/chunk-3jjc06nd.js +0 -3
  430. package/dist/chunk-3z8ajtxp.js +0 -2
  431. package/dist/chunk-4b3g7acq.js +0 -2
  432. package/dist/chunk-4jkg9p4g.js +0 -2
  433. package/dist/chunk-4xmbve71.js +0 -4
  434. package/dist/chunk-54qxv3er.js +0 -2
  435. package/dist/chunk-5bz1bzsw.js +0 -2
  436. package/dist/chunk-5dk4xga8.js +0 -2
  437. package/dist/chunk-5my9w4vd.js +0 -2
  438. package/dist/chunk-5tqygmg9.js +0 -2
  439. package/dist/chunk-7dd374an.js +0 -2
  440. package/dist/chunk-7s7txz2j.js +0 -2
  441. package/dist/chunk-8hbwf0qe.js +0 -2
  442. package/dist/chunk-8yj3q7n2.js +0 -2
  443. package/dist/chunk-9eqezb4k.js +0 -2
  444. package/dist/chunk-9xfv8jdn.js +0 -2
  445. package/dist/chunk-a3s36z4s.js +0 -3
  446. package/dist/chunk-a414w7ah.js +0 -3
  447. package/dist/chunk-am6tss41.js +0 -2
  448. package/dist/chunk-b65w6x23.js +0 -2
  449. package/dist/chunk-cv2j9sjp.js +0 -2
  450. package/dist/chunk-d1trg76g.js +0 -2
  451. package/dist/chunk-dgm4gxkj.js +0 -2
  452. package/dist/chunk-e6ddpdxn.js +0 -2
  453. package/dist/chunk-e9znmqdj.js +0 -2
  454. package/dist/chunk-eyfdn4p3.js +0 -2
  455. package/dist/chunk-fcqwzmkd.js +0 -2
  456. package/dist/chunk-fkwafga0.js +0 -2
  457. package/dist/chunk-gap8n0vv.js +0 -5
  458. package/dist/chunk-j5rd55qs.js +0 -3
  459. package/dist/chunk-j9q2s4kq.js +0 -2
  460. package/dist/chunk-jnena0v6.js +0 -2
  461. package/dist/chunk-kjswq0tx.js +0 -2
  462. package/dist/chunk-kkps1qd4.js +0 -4
  463. package/dist/chunk-mpnv2rht.js +0 -2
  464. package/dist/chunk-mtydzse4.js +0 -2
  465. package/dist/chunk-mw9k08ky.js +0 -3
  466. package/dist/chunk-px6nrr87.js +0 -2
  467. package/dist/chunk-pzmd5d3m.js +0 -2
  468. package/dist/chunk-q5az5kp2.js +0 -4
  469. package/dist/chunk-qqm07rfv.js +0 -2
  470. package/dist/chunk-qv7kkv47.js +0 -2
  471. package/dist/chunk-rq04p6pn.js +0 -3
  472. package/dist/chunk-rx9sdjtn.js +0 -2
  473. package/dist/chunk-s0b5g8nc.js +0 -2
  474. package/dist/chunk-sf1z4r7v.js +0 -2
  475. package/dist/chunk-syp06z39.js +0 -2
  476. package/dist/chunk-t6cfjn19.js +0 -2
  477. package/dist/chunk-vsff9djs.js +0 -2
  478. package/dist/chunk-vvq50011.js +0 -2
  479. package/dist/chunk-wkvm8f2e.js +0 -2
  480. package/dist/chunk-ww223tm5.js +0 -2
  481. package/dist/chunk-x0tbzjqc.js +0 -2
  482. package/dist/chunk-x480gyp7.js +0 -2
  483. package/dist/chunk-yjhypkmc.js +0 -2
@@ -0,0 +1,801 @@
1
+ //! Account-owned gateway configuration and revocation. Secrets never cross the webview boundary.
2
+ //! The host owns the account: it binds the signed-in identity and passes a fresh access token for
3
+ //! each refresh. An application without an ALwith account never calls these commands.
4
+ use super::*;
5
+ use std::sync::Mutex;
6
+ use std::time::Duration;
7
+
8
+ pub const ID: &str = "litellm";
9
+ const MODEL_PREFIX: &str = "gateway:litellm:";
10
+
11
+ /// Sessions whose account model is no longer available; the payload is a [`RevokedSessions`].
12
+ pub const REVOKED_EVENT: &str = "providers:managed-revoked";
13
+
14
+ #[derive(Clone, Serialize)]
15
+ #[serde(rename_all = "camelCase")]
16
+ pub struct RevokedSessions {
17
+ session_ids: Vec<String>,
18
+ }
19
+ impl RevokedSessions {
20
+ fn emit(&self, app: &AppHandle) {
21
+ if let Err(error) = app.emit(REVOKED_EVENT, self) {
22
+ log::warn!("Provider catalog: cannot emit {REVOKED_EVENT}: {error}");
23
+ }
24
+ }
25
+ }
26
+
27
+ #[derive(Clone, Debug, Deserialize, Serialize)]
28
+ pub(super) struct Cache {
29
+ pub account: Account,
30
+ pub provider: Option<CustomProvider>,
31
+ }
32
+ #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
33
+ #[serde(rename_all = "camelCase", deny_unknown_fields)]
34
+ pub struct Account {
35
+ pub api_base_url: String,
36
+ pub user_uuid: String,
37
+ }
38
+ #[derive(Default)]
39
+ pub(super) struct Gate {
40
+ pub generation: u64,
41
+ pub account: Option<Account>,
42
+ pub targets: BTreeSet<String>,
43
+ pub routes: BTreeMap<String, Route>,
44
+ pub models: BTreeSet<String>,
45
+ pub realtime: BTreeMap<String, String>,
46
+ }
47
+ #[derive(Clone)]
48
+ pub(super) struct Route {
49
+ pub model: String,
50
+ pub agent: String,
51
+ pub generation: u64,
52
+ }
53
+ impl Gate {
54
+ fn invalidate(&mut self) -> Result<(), String> {
55
+ self.generation = self.generation.checked_add(1).ok_or("Account generation exhausted")?;
56
+ self.account = None;
57
+ self.models.clear();
58
+ Ok(())
59
+ }
60
+ fn check_selection(&self, requested: Option<&str>, session: Option<&str>) -> Result<(), String> {
61
+ if let Some(model) = requested
62
+ && model.starts_with(MODEL_PREFIX)
63
+ && (self.account.is_none() || !self.models.contains(model))
64
+ {
65
+ return Err("The selected ALwith account model is unavailable".into());
66
+ }
67
+ if let Some(route) = session.and_then(|session| self.routes.get(session))
68
+ && (self.account.is_none() || route.generation != self.generation || !self.models.contains(&route.model))
69
+ {
70
+ return Err("The ALwith account changed. Select a model before sending".into());
71
+ }
72
+ Ok(())
73
+ }
74
+ }
75
+ fn model_ids(provider: Option<&CustomProvider>) -> BTreeSet<String> {
76
+ provider
77
+ .into_iter()
78
+ .flat_map(|provider| provider.models.iter())
79
+ .map(|model| {
80
+ let encoded: String = url_model_id(&model.api_id);
81
+ format!("{MODEL_PREFIX}{encoded}")
82
+ })
83
+ .collect()
84
+ }
85
+ fn url_model_id(id: &str) -> String {
86
+ // encodeURIComponent's unescaped bytes, matching gatewayModelId in the adapter.
87
+ id.as_bytes()
88
+ .iter()
89
+ .map(|byte| {
90
+ if byte.is_ascii_alphanumeric() || b"-_.!~*'()".contains(byte) {
91
+ (*byte as char).to_string()
92
+ } else {
93
+ format!("%{byte:02X}")
94
+ }
95
+ })
96
+ .collect()
97
+ }
98
+ #[derive(Default)]
99
+ pub(super) struct State {
100
+ pub gate: Mutex<Gate>,
101
+ pub transition: tokio::sync::Mutex<()>,
102
+ pub refresh: tokio::sync::Mutex<()>,
103
+ }
104
+
105
+ #[derive(Deserialize)]
106
+ struct IssuedProvider {
107
+ name: String,
108
+ base_url: String,
109
+ api_key: String,
110
+ #[serde(default)]
111
+ hidden: bool,
112
+ models: Vec<IssuedModel>,
113
+ }
114
+ #[derive(Deserialize)]
115
+ struct IssuedModel {
116
+ api_id: String,
117
+ label: String,
118
+ context_window: Option<u64>,
119
+ description: Option<String>,
120
+ }
121
+
122
+ pub(super) fn parse_catalog(body: &str) -> Result<Option<CustomProvider>, String> {
123
+ let rows: Vec<Value> = serde_json::from_str(body).map_err(|_| "Invalid ALwith provider response")?;
124
+ let mut selected = rows.into_iter().filter(|row| row["provider_id"] == ID);
125
+ let Some(value) = selected.next() else { return Ok(None) };
126
+ if selected.next().is_some() {
127
+ return Err("Duplicate ALwith provider".into());
128
+ }
129
+ if value["api_key"].as_str().is_none_or(|key| key.trim().is_empty()) {
130
+ return Ok(None);
131
+ }
132
+ let provider: IssuedProvider = serde_json::from_value(value).map_err(|_| "Invalid ALwith provider metadata")?;
133
+ if provider.hidden {
134
+ return Ok(None);
135
+ }
136
+ let mut ids = BTreeSet::new();
137
+ let models = provider
138
+ .models
139
+ .into_iter()
140
+ .map(|model| {
141
+ if model.api_id.trim().is_empty()
142
+ || model.label.trim().is_empty()
143
+ || model.context_window == Some(0)
144
+ || !ids.insert(model.api_id.clone())
145
+ {
146
+ return Err("Invalid or duplicate ALwith model metadata".to_string());
147
+ }
148
+ Ok(CustomModel {
149
+ api_id: model.api_id,
150
+ label: model.label,
151
+ context_window: model.context_window,
152
+ description: model.description,
153
+ })
154
+ })
155
+ .collect::<Result<Vec<_>, _>>()?;
156
+ if models.is_empty() {
157
+ return Ok(None);
158
+ }
159
+ if provider.name.trim().is_empty() {
160
+ return Err("Missing ALwith provider name".into());
161
+ }
162
+ Ok(Some(CustomProvider {
163
+ id: ID.into(),
164
+ name: provider.name,
165
+ base_url: responses_base_url(&provider.base_url)?,
166
+ models,
167
+ api_key: provider.api_key,
168
+ }))
169
+ }
170
+
171
+ fn responses_base_url(raw: &str) -> Result<String, String> {
172
+ // Account-issued gateways may use internal HTTP, as in the supported /v1/responses contract.
173
+ let url = reqwest::Url::parse(raw.trim()).map_err(|_| "Invalid ALwith gateway URL")?;
174
+ if !matches!(url.scheme(), "http" | "https")
175
+ || url.host_str().is_none()
176
+ || url.query().is_some()
177
+ || url.fragment().is_some()
178
+ || !url.username().is_empty()
179
+ || url.password().is_some()
180
+ {
181
+ return Err("Invalid ALwith gateway URL".into());
182
+ }
183
+ let base = url.as_str().trim_end_matches('/').to_string();
184
+ match url.path().trim_end_matches('/') {
185
+ "" => Ok(format!("{base}/v1")),
186
+ path if path.ends_with("/v1") => Ok(base),
187
+ _ => Err("ALwith gateway must supply a root URL or an API base ending in /v1".into()),
188
+ }
189
+ }
190
+
191
+ fn main_window(window: &tauri::WebviewWindow) -> Result<(), String> {
192
+ if window.label() != "main" {
193
+ return Err("ALwith account changes belong to the main window".into());
194
+ }
195
+ Ok(())
196
+ }
197
+ fn validate_account(account: &Account) -> Result<(), String> {
198
+ if !matches!(account.api_base_url.as_str(), "https://api.alwith.ai/service" | "https://api-dev.alwith.ai/service")
199
+ || account.user_uuid.trim().is_empty()
200
+ {
201
+ return Err("Invalid ALwith account identity".into());
202
+ }
203
+ Ok(())
204
+ }
205
+
206
+ #[tauri::command]
207
+ pub(crate) async fn providers_account_bind(window: tauri::WebviewWindow, account: Account) -> Result<u64, String> {
208
+ main_window(&window)?;
209
+ validate_account(&account)?;
210
+ let app = window.app_handle();
211
+ let state = app.state::<Providers>();
212
+ let _transition = state.managed.transition.lock().await;
213
+ let mut inner = state.inner.lock().await;
214
+ let generation = {
215
+ let mut gate = state.managed.gate.lock().unwrap();
216
+ if gate.account.as_ref() == Some(&account) {
217
+ return Ok(gate.generation);
218
+ }
219
+ if !gate.targets.is_empty() {
220
+ return Err("Previous ALwith provider cleanup is incomplete; retry logout".into());
221
+ }
222
+ gate.generation = gate.generation.checked_add(1).ok_or("Account generation exhausted")?;
223
+ gate.account = Some(account.clone());
224
+ gate.generation
225
+ };
226
+ inner.managed_active = inner.saved.managed.as_ref().is_some_and(|cache| cache.account == account);
227
+ state.managed.gate.lock().unwrap().models = if inner.managed_active {
228
+ model_ids(inner.saved.managed.as_ref().and_then(|cache| cache.provider.as_ref()))
229
+ } else {
230
+ BTreeSet::new()
231
+ };
232
+ inner.applied_revision = None;
233
+ emit(app, &inner.snapshot());
234
+ Ok(generation)
235
+ }
236
+
237
+ #[tauri::command]
238
+ pub(crate) async fn providers_refresh_managed(
239
+ window: tauri::WebviewWindow, generation: u64, access_token: String,
240
+ ) -> Result<Snapshot, Value> {
241
+ main_window(&window).map_err(|message| json!({"message":message}))?;
242
+ let app = window.app_handle();
243
+ let state = app.state::<Providers>();
244
+ let _refresh = state.managed.refresh.lock().await;
245
+ let account = {
246
+ let gate = state.managed.gate.lock().unwrap();
247
+ if gate.generation != generation {
248
+ return Err(json!({"message":"ALwith account changed"}));
249
+ }
250
+ gate.account.clone().ok_or_else(|| json!({"message":"Sign in before loading ALwith models"}))?
251
+ };
252
+ if access_token.trim().is_empty() {
253
+ return Err(json!({"message":"Missing ALwith access token"}));
254
+ }
255
+ let result = fetch_catalog(&account.api_base_url, &access_token).await;
256
+ let mut inner = state.inner.lock().await;
257
+ {
258
+ let mut gate = state.managed.gate.lock().unwrap();
259
+ if gate.generation != generation || gate.account.as_ref() != Some(&account) {
260
+ return Err(json!({"message":"ALwith account changed during refresh"}));
261
+ }
262
+ let provider = match result {
263
+ Ok(provider) => provider,
264
+ Err(error) => {
265
+ inner.error = Some("ALwith model configuration refresh failed".into());
266
+ emit(app, &inner.snapshot());
267
+ return Err(error);
268
+ }
269
+ };
270
+ let mut next = inner.saved.clone();
271
+ next.managed = Some(Cache { account, provider });
272
+ next.revision = next.revision.checked_add(1).ok_or_else(|| json!({"message":"Provider revision exhausted"}))?;
273
+ persist(&state.path, &next).map_err(|_| json!({"message":"Cannot save ALwith model configuration"}))?;
274
+ gate.models = model_ids(next.managed.as_ref().and_then(|cache| cache.provider.as_ref()));
275
+ RevokedSessions {
276
+ session_ids: gate
277
+ .routes
278
+ .iter()
279
+ .filter(|(_, route)| !gate.models.contains(&route.model))
280
+ .map(|(id, _)| id.clone())
281
+ .collect(),
282
+ }
283
+ .emit(app);
284
+ inner.saved = next;
285
+ inner.managed_active = true;
286
+ inner.error = None;
287
+ }
288
+ let snapshot = inner.snapshot();
289
+ emit(app, &snapshot);
290
+ drop(inner);
291
+ schedule_apply(app);
292
+ Ok(snapshot)
293
+ }
294
+
295
+ async fn fetch_catalog(base: &str, token: &str) -> Result<Option<CustomProvider>, Value> {
296
+ let client = reqwest::Client::builder()
297
+ .timeout(Duration::from_secs(20))
298
+ .redirect(reqwest::redirect::Policy::none())
299
+ .build()
300
+ .map_err(|_| json!({"message":"Cannot create ALwith configuration client"}))?;
301
+ let response = client
302
+ .get(format!("{base}/api/v1/providers"))
303
+ .bearer_auth(token)
304
+ .send()
305
+ .await
306
+ .map_err(|_| json!({"message":"ALwith configuration request failed"}))?;
307
+ if !response.status().is_success() {
308
+ return Err(json!({"status":response.status().as_u16(),"message":"ALwith configuration request rejected"}));
309
+ }
310
+ let body = response.text().await.map_err(|_| json!({"message":"Cannot read ALwith configuration response"}))?;
311
+ parse_catalog(&body).map_err(|message| json!({"message":message}))
312
+ }
313
+
314
+ #[tauri::command]
315
+ pub(crate) async fn providers_clear_managed(window: tauri::WebviewWindow) -> Result<(), String> {
316
+ main_window(&window)?;
317
+ clear(window.app_handle()).await
318
+ }
319
+
320
+ pub(super) async fn clear(app: &AppHandle) -> Result<(), String> {
321
+ let state = app.state::<Providers>();
322
+ // Invalidate before waiting for any network operation or admission lock.
323
+ {
324
+ let mut gate = state.managed.gate.lock().unwrap();
325
+ gate.invalidate()?;
326
+ RevokedSessions { session_ids: gate.routes.keys().cloned().collect() }.emit(app);
327
+ }
328
+ let _transition = tokio::time::timeout(Duration::from_secs(10), state.managed.transition.lock())
329
+ .await
330
+ .map_err(|_| "ALwith account transition did not settle; cleanup is incomplete")?;
331
+ state.managed.gate.lock().unwrap().invalidate()?;
332
+ let saved_error = {
333
+ let mut inner = tokio::time::timeout(Duration::from_secs(10), state.inner.lock())
334
+ .await
335
+ .map_err(|_| "ALwith provider configuration did not settle; cleanup is incomplete")?;
336
+ inner.managed_active = false;
337
+ inner.applied_revision = None;
338
+ inner.saved.managed = None;
339
+ inner.saved.revision = inner.saved.revision.checked_add(1).ok_or("Provider revision exhausted")?;
340
+ let error = persist(&state.path, &inner.saved).err();
341
+ emit(app, &inner.snapshot());
342
+ error
343
+ };
344
+ let cleanup = cleanup(app).await;
345
+ if let Some(error) = saved_error {
346
+ return Err(error);
347
+ }
348
+ cleanup
349
+ }
350
+
351
+ pub(super) async fn cleanup(app: &AppHandle) -> Result<(), String> {
352
+ tokio::time::timeout(Duration::from_secs(30), cleanup_inner(app))
353
+ .await
354
+ .map_err(|_| "ALwith provider cleanup timed out; execution remains blocked")?
355
+ }
356
+
357
+ async fn cleanup_inner(app: &AppHandle) -> Result<(), String> {
358
+ let state = app.state::<Providers>();
359
+ {
360
+ let gate = state.managed.gate.lock().unwrap();
361
+ if gate.account.is_some() || gate.targets.is_empty() {
362
+ return Ok(());
363
+ }
364
+ }
365
+ let runtime = &state.runtime;
366
+ let client = runtime.current(app).map_err(|_| "Runtime unavailable; ALwith cleanup is unconfirmed")?;
367
+ // Drain accepted lifecycle/configuration operations before taking the cancellation snapshot.
368
+ // New requests see the invalid gate. Never hold admission while waiting for turn termination.
369
+ let admission = tokio::time::timeout(Duration::from_secs(10), runtime.admission(app).lock())
370
+ .await
371
+ .map_err(|_| "ALwith request admission did not settle")?;
372
+ let (targets, routes, realtime) = {
373
+ let gate = state.managed.gate.lock().unwrap();
374
+ (gate.targets.clone(), gate.routes.clone(), gate.realtime.clone())
375
+ };
376
+ drop(admission);
377
+ let result = tokio::time::timeout(Duration::from_secs(10), async {
378
+ for (session, agent) in &realtime {
379
+ client
380
+ .acp_request(agent, "_codex/realtime/stop", json!({"sessionId":session}), None, None)
381
+ .await
382
+ .map_err(|error| format!("ALwith Runtime cleanup failed ({})", error.code))?;
383
+ state.managed.gate.lock().unwrap().realtime.remove(session);
384
+ }
385
+ for session in
386
+ client.run_states().await.map_err(|error| format!("ALwith Runtime cleanup failed ({})", error.code))?
387
+ {
388
+ if matches!(session.state, alwith_api::RunState::Running | alwith_api::RunState::RequiresAction)
389
+ && let Some(route) = routes.get(&session.session_id)
390
+ {
391
+ client
392
+ .cancel(&route.agent, &session.session_id, None)
393
+ .await
394
+ .map_err(|error| format!("ALwith Runtime cleanup failed ({})", error.code))?;
395
+ }
396
+ }
397
+ loop {
398
+ let active =
399
+ client.run_states().await.map_err(|error| format!("ALwith Runtime cleanup failed ({})", error.code))?;
400
+ if !active.iter().any(|session| {
401
+ routes.contains_key(&session.session_id)
402
+ && matches!(session.state, alwith_api::RunState::Running | alwith_api::RunState::RequiresAction)
403
+ }) {
404
+ break;
405
+ }
406
+ tokio::time::sleep(Duration::from_millis(50)).await;
407
+ }
408
+ Ok::<(), String>(())
409
+ })
410
+ .await
411
+ .map_err(|_| "ALwith turn cancellation timed out".to_string())
412
+ .and_then(|result| result);
413
+ if let Err(error) = result {
414
+ // Dedicated auxiliary agents can be stopped without interrupting unrelated main conversations.
415
+ for target in targets.iter().filter(|target| target.as_str() != MAIN_AGENT) {
416
+ if stop_dedicated(&client, target).await
417
+ && runtime.current(app).is_ok_and(|current| Arc::ptr_eq(&current, &client))
418
+ {
419
+ state.managed.gate.lock().unwrap().targets.remove(target);
420
+ }
421
+ }
422
+ return Err(error);
423
+ }
424
+ for target in targets {
425
+ let live = client.agents().await.map_err(|error| format!("ALwith Runtime cleanup failed ({})", error.code))?;
426
+ if live.iter().any(|agent| agent["agentId"] == target) {
427
+ let removed = tokio::time::timeout(
428
+ Duration::from_secs(10),
429
+ client.acp_request(
430
+ &target,
431
+ "providers/disable",
432
+ json!({"providerId":"openai","_meta":{"codex":{"id":ID}}}),
433
+ None,
434
+ None,
435
+ ),
436
+ )
437
+ .await;
438
+ if !matches!(removed, Ok(Ok(_))) && !stop_dedicated(&client, &target).await {
439
+ return Err("ALwith provider cleanup is incomplete; wait for active sessions and retry".into());
440
+ }
441
+ }
442
+ // A stale Runtime cannot acknowledge cleanup for its replacement.
443
+ if !runtime.current(app).is_ok_and(|current| Arc::ptr_eq(&current, &client)) {
444
+ return Err("Runtime changed during ALwith cleanup".into());
445
+ }
446
+ state.managed.gate.lock().unwrap().targets.remove(&target);
447
+ if target == MAIN_AGENT {
448
+ let mut inner = state.inner.lock().await;
449
+ inner.applied.remove(ID);
450
+ inner.applied_revision = None;
451
+ }
452
+ }
453
+ Ok(())
454
+ }
455
+
456
+ async fn stop_dedicated(client: &RuntimeClient, target: &str) -> bool {
457
+ if target == MAIN_AGENT {
458
+ return false;
459
+ }
460
+ matches!(
461
+ tokio::time::timeout(Duration::from_secs(5), async {
462
+ client.stop(target, None).await?;
463
+ let live = client.agents().await?;
464
+ Ok::<bool, ResponseError>(!live.iter().any(|agent| agent["agentId"] == target))
465
+ })
466
+ .await,
467
+ Ok(Ok(true))
468
+ )
469
+ }
470
+
471
+ pub(super) fn selected_model(value: &Value) -> Option<&str> {
472
+ value
473
+ .get("configOptions")?
474
+ .as_array()?
475
+ .iter()
476
+ .find(|option| option["category"] == "model" || option["configId"] == "model")?
477
+ .get("currentValue")?
478
+ .as_str()
479
+ }
480
+ pub fn observe(app: &AppHandle, agent: &str, session: &str, value: &Value, admitted_generation: Option<u64>) {
481
+ let Some(model) = selected_model(value) else { return };
482
+ let state = app.state::<Providers>();
483
+ let mut gate = state.managed.gate.lock().unwrap();
484
+ if model.starts_with(MODEL_PREFIX) {
485
+ let generation = admitted_generation.unwrap_or(gate.generation);
486
+ if admitted_generation.is_some() || !gate.routes.contains_key(session) {
487
+ gate.routes.insert(session.into(), Route { agent: agent.into(), generation, model: model.into() });
488
+ if gate.account.is_none() || generation != gate.generation || !gate.models.contains(model) {
489
+ RevokedSessions { session_ids: vec![session.into()] }.emit(app);
490
+ }
491
+ }
492
+ } else if admitted_generation == Some(gate.generation) {
493
+ gate.routes.remove(session);
494
+ }
495
+ }
496
+
497
+ pub fn observe_event(app: &AppHandle, event: &alwith_api::RuntimeEvent) {
498
+ match event {
499
+ alwith_api::RuntimeEvent::AcpNotification { method, params, .. }
500
+ if method == "_codex/realtime/update" && params["event"] == "closed" =>
501
+ {
502
+ if let Some(session) = params["sessionId"].as_str() {
503
+ app.state::<Providers>().managed.gate.lock().unwrap().realtime.remove(session);
504
+ }
505
+ }
506
+ alwith_api::RuntimeEvent::AcpNotification { agent_id, method, params, .. } if method == "session/update" => {
507
+ if let Some(session) = params["sessionId"].as_str() {
508
+ observe(app, agent_id, session, &params["update"], None);
509
+ }
510
+ }
511
+ alwith_api::RuntimeEvent::Inbound { agent_id, lines } => {
512
+ for line in lines {
513
+ if let Ok(frame) = serde_json::from_str::<Value>(line)
514
+ && frame["method"] == "session/update"
515
+ && let Some(session) = frame["params"]["sessionId"].as_str()
516
+ {
517
+ observe(app, agent_id, session, &frame["params"]["update"], None);
518
+ }
519
+ }
520
+ }
521
+ alwith_api::RuntimeEvent::Exit { agent_id } => {
522
+ let state = app.state::<Providers>();
523
+ let mut gate = state.managed.gate.lock().unwrap();
524
+ gate.targets.remove(agent_id);
525
+ gate.realtime.retain(|_, agent| agent != agent_id);
526
+ // Keep revoked selections across adapter restarts until explicit reselection.
527
+ }
528
+ _ => {}
529
+ }
530
+ }
531
+
532
+ /// All webview request shapes pass here, including drafts and raw ACP configuration changes.
533
+ pub fn check(app: &AppHandle, method: &str, params: Option<&Value>) -> Result<u64, String> {
534
+ let state = app.state::<Providers>();
535
+ let gate = state.managed.gate.lock().unwrap();
536
+ if method == "send" {
537
+ return Err("Use structured Runtime requests for session operations".into());
538
+ }
539
+ let Some(params) = params else { return Ok(gate.generation) };
540
+ let (method, body) = if matches!(method, "acpRequest" | "acpNotify") {
541
+ (params["method"].as_str().unwrap_or(""), &params["params"])
542
+ } else {
543
+ (method, params)
544
+ };
545
+ check_request(&gate, method, body)?;
546
+ Ok(gate.generation)
547
+ }
548
+
549
+ pub fn requires_admission(method: &str, params: Option<&Value>) -> bool {
550
+ let Some(params) = params else { return false };
551
+ matches!(method, "acpRequest" | "acpNotify")
552
+ && matches!(
553
+ params["method"].as_str(),
554
+ Some(
555
+ "_session/steering"
556
+ | "_session/goal"
557
+ | "_codex/session/goal_control"
558
+ | "_codex/session_retry"
559
+ | "_codex/session_prediction_request"
560
+ | "_codex/realtime/start"
561
+ | "_codex/realtime/appendAudio"
562
+ | "_codex/realtime/appendText"
563
+ | "_codex/realtime/appendSpeech"
564
+ )
565
+ )
566
+ }
567
+
568
+ pub fn observe_realtime(app: &AppHandle, method: &str, params: &Value) {
569
+ if method != "acpRequest" {
570
+ return;
571
+ }
572
+ let Some(session) = params["params"]["sessionId"].as_str() else {
573
+ return;
574
+ };
575
+ let state = app.state::<Providers>();
576
+ let mut gate = state.managed.gate.lock().unwrap();
577
+ match params["method"].as_str() {
578
+ Some("_codex/realtime/start") => {
579
+ if let Some(route) = gate.routes.get(session) {
580
+ let agent = route.agent.clone();
581
+ gate.realtime.insert(session.into(), agent);
582
+ }
583
+ }
584
+ Some("_codex/realtime/stop") => {
585
+ gate.realtime.remove(session);
586
+ }
587
+ _ => {}
588
+ }
589
+ }
590
+
591
+ pub fn confirms_model(method: &str, params: &Value) -> bool {
592
+ let (method, body) = if matches!(method, "acpRequest" | "acpNotify") {
593
+ (params["method"].as_str().unwrap_or(""), &params["params"])
594
+ } else {
595
+ (method, params)
596
+ };
597
+ matches!(
598
+ method,
599
+ "sessionNew"
600
+ | "session/new"
601
+ | "sessionResume"
602
+ | "session/resume"
603
+ | "sessionLoad"
604
+ | "session/load"
605
+ | "sessionFork"
606
+ | "session/fork"
607
+ ) || (method == "session/set_config_option" && body["configId"] == "model")
608
+ }
609
+
610
+ fn check_request(gate: &Gate, method: &str, body: &Value) -> Result<(), String> {
611
+ let selection = method == "session/set_config_option" && body["configId"] == "model";
612
+ let lifecycle = matches!(
613
+ method,
614
+ "sessionNew"
615
+ | "session/new"
616
+ | "sessionResume"
617
+ | "session/resume"
618
+ | "sessionLoad"
619
+ | "session/load"
620
+ | "sessionFork"
621
+ | "session/fork"
622
+ );
623
+ let execution = matches!(
624
+ method,
625
+ "prompt"
626
+ | "session/prompt"
627
+ | "_session/steering"
628
+ | "_session/goal"
629
+ | "_codex/session/goal_control"
630
+ | "_codex/session_retry"
631
+ | "_codex/session_prediction_request"
632
+ | "_codex/realtime/start"
633
+ | "_codex/realtime/appendAudio"
634
+ | "_codex/realtime/appendText"
635
+ | "_codex/realtime/appendSpeech"
636
+ );
637
+ if !(method == "session/set_config_option" || lifecycle || execution) {
638
+ return Ok(());
639
+ }
640
+ let explicit_resume = matches!(method, "sessionResume" | "session/resume")
641
+ && (body
642
+ .pointer("/_meta/alwith/accountModelSelection")
643
+ .or_else(|| body.pointer("/meta/alwith/accountModelSelection"))
644
+ == Some(&Value::Bool(true)));
645
+ let requested = if selection {
646
+ body["value"].as_str()
647
+ } else if lifecycle {
648
+ body.pointer("/_meta/alwith/model").or_else(|| body.pointer("/meta/alwith/model")).and_then(Value::as_str)
649
+ } else {
650
+ None
651
+ };
652
+ // Prompt metadata is not a model selection. Only the adapter's explicit model option
653
+ // can authorize an old session under a new account.
654
+ if explicit_resume && requested.is_none() {
655
+ return Err("Explicit model recovery requires a model".into());
656
+ }
657
+ gate.check_selection(requested, if selection || explicit_resume { None } else { body["sessionId"].as_str() })
658
+ }
659
+
660
+ #[cfg(test)]
661
+ mod tests {
662
+ use super::*;
663
+
664
+ #[test]
665
+ fn revoked_route_cannot_send_under_a_replacement_account() {
666
+ let mut gate = Gate {
667
+ account: Some(Account { api_base_url: "https://api.alwith.ai/service".into(), user_uuid: "a".into() }),
668
+ generation: 1,
669
+ ..Gate::default()
670
+ };
671
+ gate.models.insert("gateway:litellm:m".into());
672
+ gate.routes.insert(
673
+ "session".into(),
674
+ Route { agent: "codex".into(), generation: 1, model: "gateway:litellm:m".into() },
675
+ );
676
+ assert!(gate.check_selection(None, Some("session")).is_ok());
677
+ gate.invalidate().unwrap();
678
+ assert!(gate.check_selection(Some("gateway:litellm:m"), None).is_err());
679
+ gate.account = Some(Account { api_base_url: "https://api.alwith.ai/service".into(), user_uuid: "b".into() });
680
+ gate.models.insert("gateway:litellm:m".into());
681
+ assert!(gate.check_selection(None, Some("session")).is_err());
682
+ assert!(gate.check_selection(Some("gpt-native"), Some("session")).is_err());
683
+ // Only an explicit model selection validates the new model without inheriting the old route.
684
+ assert!(gate.check_selection(Some("gpt-native"), None).is_ok());
685
+ }
686
+
687
+ #[test]
688
+ fn automatic_model_hints_do_not_authorize_a_replacement_account() {
689
+ let mut gate = Gate {
690
+ account: Some(Account { api_base_url: "https://api.alwith.ai/service".into(), user_uuid: "b".into() }),
691
+ generation: 2,
692
+ ..Gate::default()
693
+ };
694
+ let model = "gateway:litellm:m";
695
+ gate.models.insert(model.into());
696
+ gate.routes.insert("old".into(), Route { agent: "codex".into(), generation: 1, model: model.into() });
697
+ assert!(gate.check_selection(Some(model), Some("old")).is_err());
698
+ }
699
+
700
+ #[test]
701
+ fn execution_hints_cannot_bypass_revocation_and_explicit_selection_can_recover() {
702
+ let mut gate = Gate::default();
703
+ gate.routes
704
+ .insert("old".into(), Route { agent: "codex".into(), generation: 0, model: "gateway:litellm:m".into() });
705
+ let body = json!({"sessionId":"old", "_meta":{"alwith":{"model":"gpt-native"}}});
706
+ for method in [
707
+ "prompt",
708
+ "session/prompt",
709
+ "_session/steering",
710
+ "_session/goal",
711
+ "_codex/session/goal_control",
712
+ "_codex/session_retry",
713
+ "_codex/session_prediction_request",
714
+ "_codex/realtime/start",
715
+ "_codex/realtime/appendAudio",
716
+ "_codex/realtime/appendText",
717
+ "_codex/realtime/appendSpeech",
718
+ "sessionResume",
719
+ "session/resume",
720
+ "sessionFork",
721
+ "session/fork",
722
+ ] {
723
+ assert!(check_request(&gate, method, &body).is_err(), "{method}");
724
+ }
725
+ assert!(
726
+ check_request(
727
+ &gate,
728
+ "session/set_config_option",
729
+ &json!({"sessionId":"old", "configId":"model", "value":"gpt-native"})
730
+ )
731
+ .is_ok()
732
+ );
733
+ assert!(
734
+ check_request(
735
+ &gate,
736
+ "session/set_config_option",
737
+ &json!({"sessionId":"old", "configId":"model", "value":"gateway:litellm:m"})
738
+ )
739
+ .is_err()
740
+ );
741
+ }
742
+
743
+ #[test]
744
+ fn explicit_resume_authorizes_only_a_valid_model_and_never_authorizes_prompt_metadata() {
745
+ let mut gate = Gate::default();
746
+ gate.routes
747
+ .insert("old".into(), Route { agent: "codex".into(), generation: 0, model: "gateway:litellm:m".into() });
748
+ let body = json!({"sessionId":"old", "_meta":{"alwith":{"model":"gpt-native", "accountModelSelection":true}}});
749
+ assert!(check_request(&gate, "session/resume", &body).is_ok());
750
+ assert!(check_request(&gate, "session/prompt", &body).is_err());
751
+ assert!(
752
+ check_request(
753
+ &gate,
754
+ "session/resume",
755
+ &json!({"sessionId":"old", "_meta":{"alwith":{"accountModelSelection":true}}})
756
+ )
757
+ .is_err()
758
+ );
759
+ assert!(check_request(&gate, "session/resume", &json!({"sessionId":"old", "_meta":{"alwith":{"accountModelSelection":true,"model":"gateway:litellm:m"}}})).is_err());
760
+ }
761
+
762
+ #[test]
763
+ fn changing_effort_is_not_an_account_model_selection() {
764
+ let mut gate = Gate::default();
765
+ gate.routes
766
+ .insert("old".into(), Route { agent: "codex".into(), generation: 0, model: "gateway:litellm:m".into() });
767
+ let body = json!({"sessionId":"old", "configId":"reasoning_effort", "value":"high"});
768
+ assert!(check_request(&gate, "session/set_config_option", &body).is_err());
769
+ assert!(!confirms_model("acpRequest", &json!({"method":"session/set_config_option", "params":body})));
770
+ assert!(confirms_model(
771
+ "acpRequest",
772
+ &json!({"method":"session/set_config_option", "params":{"configId":"model"}})
773
+ ));
774
+ }
775
+
776
+ #[test]
777
+ fn responses_endpoint_accepts_root_or_versioned_base_without_guessing_other_paths() {
778
+ assert_eq!(responses_base_url("http://localhost:8080").unwrap(), "http://localhost:8080/v1");
779
+ assert_eq!(responses_base_url("http://gateway.internal:8080").unwrap(), "http://gateway.internal:8080/v1");
780
+ for invalid in ["file:///v1", "https://key@gateway.test/v1", "https://gateway.test/v1?key=secret"] {
781
+ assert!(responses_base_url(invalid).is_err());
782
+ }
783
+ assert_eq!(responses_base_url("https://gateway.test/v1/").unwrap(), "https://gateway.test/v1");
784
+ assert_eq!(responses_base_url("https://gateway.test/proxy/v1").unwrap(), "https://gateway.test/proxy/v1");
785
+ assert!(responses_base_url("https://gateway.test/proxy").is_err());
786
+ }
787
+
788
+ #[test]
789
+ fn removing_a_model_blocks_new_requests_on_its_existing_route() {
790
+ let mut gate = Gate {
791
+ account: Some(Account { api_base_url: "https://api.alwith.ai/service".into(), user_uuid: "a".into() }),
792
+ ..Gate::default()
793
+ };
794
+ gate.routes.insert(
795
+ "session".into(),
796
+ Route { agent: "codex".into(), generation: 0, model: "gateway:litellm:removed".into() },
797
+ );
798
+ assert!(gate.check_selection(None, Some("session")).is_err());
799
+ assert!(gate.check_selection(Some("gateway:litellm:removed"), None).is_err());
800
+ }
801
+ }