@alwith/module-chat 0.5.18 → 0.5.20

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 (555) 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-0643swd4.js +2 -0
  19. package/dist/chunk-06zh85wp.js +3 -0
  20. package/dist/chunk-0p6y2t9b.js +2 -0
  21. package/dist/{chunk-fexvhys2.js → chunk-0wa9yjg3.js} +2 -2
  22. package/dist/chunk-0whxm2f0.js +2 -0
  23. package/dist/chunk-11484wvv.js +2 -0
  24. package/dist/{chunk-s55n9cby.js → chunk-1fggcrvs.js} +2 -2
  25. package/dist/chunk-1k21j77z.js +2 -0
  26. package/dist/chunk-1k697ncv.js +2 -0
  27. package/dist/chunk-1mn2t6ga.js +2 -0
  28. package/dist/{chunk-kzq1797a.js → chunk-1qyxrh0n.js} +3 -3
  29. package/dist/chunk-1r25anvg.js +2 -0
  30. package/dist/chunk-1rg3nab3.js +2 -0
  31. package/dist/chunk-20k9syde.js +1 -0
  32. package/dist/chunk-28f3zv6v.js +2 -0
  33. package/dist/{chunk-djmnmbm2.js → chunk-2f9vjmxz.js} +2 -2
  34. package/dist/chunk-2t9j90mw.js +2 -0
  35. package/dist/{chunk-qp7aywgn.js → chunk-36m8zstj.js} +2 -2
  36. package/dist/chunk-3gk86w24.js +2 -0
  37. package/dist/chunk-3ka3bt0t.js +2 -0
  38. package/dist/{chunk-65m4bm74.js → chunk-3s94ekrs.js} +2 -2
  39. package/dist/chunk-3vsc49pt.js +2 -0
  40. package/dist/{chunk-mzh48e09.js → chunk-3yxjh7b1.js} +2 -2
  41. package/dist/{chunk-2pj3pcc7.js → chunk-42atrgm1.js} +2 -2
  42. package/dist/{chunk-as1cvbzm.js → chunk-48fj5m0p.js} +2 -2
  43. package/dist/chunk-4bb6dzzs.js +2 -0
  44. package/dist/chunk-4d853988.js +2 -0
  45. package/dist/chunk-4gyd9hx9.js +2 -0
  46. package/dist/chunk-4p6svs37.js +2 -0
  47. package/dist/chunk-4ygyb91q.js +2 -0
  48. package/dist/chunk-581e33tz.js +2 -0
  49. package/dist/{chunk-hfaarm10.js → chunk-5a6xc345.js} +2 -2
  50. package/dist/chunk-5ap6fvrp.js +2 -0
  51. package/dist/chunk-5m7vc4s6.js +2 -0
  52. package/dist/chunk-615a0yhh.js +2 -0
  53. package/dist/chunk-62jm1gct.js +2 -0
  54. package/dist/{chunk-ykp85wc1.js → chunk-667z0pac.js} +2 -2
  55. package/dist/chunk-6syhjege.js +2 -0
  56. package/dist/{chunk-m9en74e3.js → chunk-6t5war9h.js} +2 -2
  57. package/dist/chunk-7z4gtfkd.js +2 -0
  58. package/dist/{chunk-4z4tec0p.js → chunk-855w49k0.js} +2 -2
  59. package/dist/chunk-8akwfgkq.js +2 -0
  60. package/dist/chunk-8c8ncw1m.js +2 -0
  61. package/dist/chunk-8mgypdap.js +2 -0
  62. package/dist/chunk-95mynf7q.js +1289 -0
  63. package/dist/{chunk-01denvg2.js → chunk-9jp5t3qq.js} +5 -5
  64. package/dist/chunk-9mky3b7v.js +2 -0
  65. package/dist/chunk-a63k8tht.js +2 -0
  66. package/dist/chunk-acb8t4jt.js +2 -0
  67. package/dist/chunk-adk7aeyt.js +2 -0
  68. package/dist/{chunk-rvr6zj7p.js → chunk-agqnt7xq.js} +2 -2
  69. package/dist/chunk-annzfgfq.js +4 -0
  70. package/dist/{chunk-qz8gpb9j.js → chunk-azfmr99x.js} +2 -2
  71. package/dist/chunk-b12v22de.js +2 -0
  72. package/dist/{chunk-w390ewja.js → chunk-b18zr059.js} +2 -2
  73. package/dist/chunk-bbyscgdd.js +2 -0
  74. package/dist/chunk-bfhfbrzt.js +2 -0
  75. package/dist/{chunk-5x4an3fb.js → chunk-bg03czcx.js} +2 -2
  76. package/dist/chunk-bvgqsaey.js +2 -0
  77. package/dist/chunk-c32z3wjq.js +2 -0
  78. package/dist/chunk-ckyat78p.js +2 -0
  79. package/dist/chunk-cvz3k5gk.js +2 -0
  80. package/dist/chunk-d0vhdr07.js +2 -0
  81. package/dist/chunk-d257n8gj.js +2 -0
  82. package/dist/chunk-dfgak1md.js +2 -0
  83. package/dist/{chunk-d7gjvz8z.js → chunk-drhzcs6e.js} +2 -2
  84. package/dist/{chunk-2qhbm5y9.js → chunk-dte0n4kf.js} +2 -2
  85. package/dist/chunk-erjscd1r.js +4 -0
  86. package/dist/chunk-f1x483c9.js +2 -0
  87. package/dist/chunk-f2w2sct6.js +2 -0
  88. package/dist/{chunk-6nnwmqqp.js → chunk-f5gsffbv.js} +2 -2
  89. package/dist/chunk-feg5rp9g.js +2 -0
  90. package/dist/chunk-ffspd86m.js +2 -0
  91. package/dist/chunk-fh3pjhe6.js +2 -0
  92. package/dist/chunk-fnpf84rf.js +4 -0
  93. package/dist/chunk-g2qcyqc6.js +2 -0
  94. package/dist/chunk-g44hhdha.js +2 -0
  95. package/dist/chunk-g9t2d8hg.js +2 -0
  96. package/dist/chunk-g9yg36dh.js +3 -0
  97. package/dist/{chunk-m4dgha79.js → chunk-gha517v4.js} +2 -2
  98. package/dist/chunk-grr1k5zn.js +2 -0
  99. package/dist/{chunk-4zzhckab.js → chunk-gsfgdnfp.js} +2 -2
  100. package/dist/chunk-h491shsg.js +2 -0
  101. package/dist/chunk-ha46rhzj.js +2 -0
  102. package/dist/{chunk-39sbgvd3.js → chunk-hd7bk591.js} +2 -2
  103. package/dist/chunk-heyqzkxq.js +2 -0
  104. package/dist/chunk-hp4a0e8c.js +2 -0
  105. package/dist/chunk-j69t1f4a.js +2 -0
  106. package/dist/chunk-j8v3sfpv.js +2 -0
  107. package/dist/{chunk-1wpdb17m.js → chunk-jgd6dcgy.js} +2 -2
  108. package/dist/chunk-jmb8r6aj.js +2 -0
  109. package/dist/chunk-jwt7q6yx.js +4 -0
  110. package/dist/chunk-jxntqarp.js +2 -0
  111. package/dist/chunk-k64wvbbc.js +2 -0
  112. package/dist/{chunk-n56csv51.js → chunk-k7ye738q.js} +2 -2
  113. package/dist/chunk-kbeme4w0.js +3 -0
  114. package/dist/{chunk-wrkwz65x.js → chunk-kc56dhwd.js} +2 -2
  115. package/dist/{chunk-2g8targj.js → chunk-kmdag4vy.js} +2 -2
  116. package/dist/chunk-kq48hbd5.js +2 -0
  117. package/dist/chunk-ktvh4yb5.js +2 -0
  118. package/dist/chunk-kz1kjzmq.js +2 -0
  119. package/dist/chunk-m271yxxm.js +2 -0
  120. package/dist/chunk-mj7094yh.js +2 -0
  121. package/dist/chunk-mr6k70s4.js +2 -0
  122. package/dist/chunk-mv51zgj1.js +2 -0
  123. package/dist/{chunk-dnsmr5nf.js → chunk-mvs2dzyt.js} +2 -2
  124. package/dist/chunk-mz8a6292.js +2 -0
  125. package/dist/chunk-n5v1h0sk.js +2 -0
  126. package/dist/{chunk-w38vbf7h.js → chunk-n66yy1m1.js} +2 -2
  127. package/dist/chunk-n9gq2wbz.js +3 -0
  128. package/dist/chunk-nxyrrmz8.js +2 -0
  129. package/dist/chunk-p7dd93e5.js +2 -0
  130. package/dist/chunk-p8g927x6.js +2 -0
  131. package/dist/chunk-pk2rvqd0.js +2 -0
  132. package/dist/{chunk-c2bkhrcc.js → chunk-pprt7ntb.js} +4 -4
  133. package/dist/{chunk-kv0tnq8g.js → chunk-pwjz3yxb.js} +2 -2
  134. package/dist/{chunk-yy4tw3nj.js → chunk-px1ehzwc.js} +2 -2
  135. package/dist/chunk-pzjag1mt.js +4 -0
  136. package/dist/chunk-q2gfd4jk.js +2 -0
  137. package/dist/{chunk-jp73gpbp.js → chunk-q9ef9n7b.js} +2 -2
  138. package/dist/chunk-q9zawfn1.js +2 -0
  139. package/dist/chunk-qd1z91fm.js +2 -0
  140. package/dist/chunk-qdg5zphd.js +2 -0
  141. package/dist/chunk-qn6ppn0r.js +2 -0
  142. package/dist/{chunk-ahtyazfy.js → chunk-qwfw4xpn.js} +2 -2
  143. package/dist/chunk-r7s7kx38.js +3 -0
  144. package/dist/chunk-r9sweaq4.js +2 -0
  145. package/dist/{chunk-cazdmcwd.js → chunk-rbv1scqm.js} +2 -2
  146. package/dist/{chunk-fydcbjsx.js → chunk-rjkpe1fw.js} +3 -3
  147. package/dist/{chunk-yh9qdb2k.js → chunk-rjw63t34.js} +3 -3
  148. package/dist/chunk-rkfq0c0p.js +2 -0
  149. package/dist/chunk-rq5e0922.js +2 -0
  150. package/dist/chunk-s4wjckd1.js +7 -0
  151. package/dist/chunk-s8s65pj2.js +2 -0
  152. package/dist/chunk-ssxbxanb.js +2 -0
  153. package/dist/{chunk-d5w1nvrz.js → chunk-swpy2b9a.js} +2 -2
  154. package/dist/{chunk-2r3sfmyf.js → chunk-t7drk9ja.js} +2 -2
  155. package/dist/chunk-tpbqg729.js +2 -0
  156. package/dist/chunk-ttn8ss6b.js +2 -0
  157. package/dist/chunk-tv0fwt2g.js +2 -0
  158. package/dist/chunk-v5pbaf9x.js +2 -0
  159. package/dist/chunk-vbab9hc4.js +2 -0
  160. package/dist/{chunk-nxk65z2e.js → chunk-vfhxerxt.js} +2 -2
  161. package/dist/chunk-vnsgjnp3.js +2 -0
  162. package/dist/{chunk-0mze2qnw.js → chunk-vt6cyes7.js} +2 -2
  163. package/dist/chunk-vzgv360q.js +2 -0
  164. package/dist/{chunk-01dqjas2.js → chunk-wccx911q.js} +2 -2
  165. package/dist/{chunk-rf9yxbes.js → chunk-wgrmjfyp.js} +2 -2
  166. package/dist/chunk-wvry7t79.js +2 -0
  167. package/dist/chunk-x2nemdjf.js +2 -0
  168. package/dist/{chunk-7g79m27w.js → chunk-x99fyd88.js} +2 -2
  169. package/dist/chunk-xdm2are3.js +2 -0
  170. package/dist/chunk-xft0s40a.js +3 -0
  171. package/dist/chunk-y0q6jwq4.js +2 -0
  172. package/dist/chunk-y6kzbbya.js +2 -0
  173. package/dist/{chunk-2swp3nfs.js → chunk-y97ne5kj.js} +2 -2
  174. package/dist/chunk-yakar0e2.js +2 -0
  175. package/dist/chunk-yg3xhn5m.js +2 -0
  176. package/dist/{chunk-txn8v2yc.js → chunk-z3nybrbb.js} +2 -2
  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/styles.css +2 -1
  190. package/dist/codex/timeline-virtualizer.js +1 -1
  191. package/dist/codex/turn-activity.js +1 -1
  192. package/dist/codex/user-message.js +1 -1
  193. package/dist/codex/virtualized-turn-list.js +1 -1
  194. package/dist/collections/collection-emoji.d.ts +4 -0
  195. package/dist/collections/collection-emoji.js +1 -0
  196. package/dist/collections/collection-menu.d.ts +15 -0
  197. package/dist/collections/collection-menu.js +1 -0
  198. package/dist/collections/collection-panel.d.ts +11 -0
  199. package/dist/collections/collection-panel.js +1 -0
  200. package/dist/collections/collections.d.ts +6 -0
  201. package/dist/collections/collections.js +1 -0
  202. package/dist/collections/host.d.ts +19 -0
  203. package/dist/collections/host.js +1 -0
  204. package/dist/collections/locales.d.ts +71 -0
  205. package/dist/collections/locales.js +1 -0
  206. package/dist/collections/model.d.ts +95 -0
  207. package/dist/collections/model.js +1 -0
  208. package/dist/collections/store.d.ts +30 -0
  209. package/dist/collections/store.js +1 -0
  210. package/dist/composer/completion-filter.js +1 -1
  211. package/dist/composer/completion-menu.js +1 -1
  212. package/dist/composer/completion-trigger.js +1 -1
  213. package/dist/composer/effort-slider.js +1 -1
  214. package/dist/composer/menu-radio.js +1 -1
  215. package/dist/composer/model-select.d.ts +1 -1
  216. package/dist/composer/model-select.js +1 -1
  217. package/dist/composer/permission-mode-select.js +1 -1
  218. package/dist/composer/prompt-input-attachments.js +1 -1
  219. package/dist/composer/prompt-input-clipboard.js +1 -1
  220. package/dist/composer/prompt-input-context.js +1 -1
  221. package/dist/composer/prompt-input-textarea.d.ts +1 -1
  222. package/dist/composer/prompt-input-textarea.js +1 -1
  223. package/dist/composer/prompt-input.d.ts +1 -1
  224. package/dist/composer/prompt-input.js +1 -1
  225. package/dist/conversation/action-card.js +1 -1
  226. package/dist/conversation/composer/composer.js +1 -1
  227. package/dist/conversation/composer/config-options.js +1 -1
  228. package/dist/conversation/composer/context.js +1 -1
  229. package/dist/conversation/composer/drafts.js +1 -1
  230. package/dist/conversation/composer/file-items.js +1 -1
  231. package/dist/conversation/composer/long-text.js +1 -1
  232. package/dist/conversation/composer/mention-chips.js +1 -1
  233. package/dist/conversation/composer/mention-uri.js +1 -1
  234. package/dist/conversation/composer/model-menu.js +1 -1
  235. package/dist/conversation/composer/pasted-text-attachment.js +1 -1
  236. package/dist/conversation/composer/permission-mode-menu.js +1 -1
  237. package/dist/conversation/composer/prediction.js +1 -1
  238. package/dist/conversation/composer/slash-command-button.js +1 -1
  239. package/dist/conversation/composer/submit-button.js +1 -1
  240. package/dist/conversation/composer/usage-meter.js +1 -1
  241. package/dist/conversation/connection-notice.d.ts +8 -0
  242. package/dist/conversation/connection-notice.js +1 -0
  243. package/dist/conversation/context.js +1 -1
  244. package/dist/conversation/conversation-body.js +1 -1
  245. package/dist/conversation/conversation-search.d.ts +8 -0
  246. package/dist/conversation/conversation-search.js +1 -0
  247. package/dist/conversation/conversation-view.d.ts +1 -0
  248. package/dist/conversation/conversation-view.js +1 -1
  249. package/dist/conversation/conversation.d.ts +3 -0
  250. package/dist/conversation/conversation.js +1 -1
  251. package/dist/conversation/diff-modal.js +1 -1
  252. package/dist/conversation/draft-project-picker.d.ts +7 -0
  253. package/dist/conversation/draft-project-picker.js +1 -0
  254. package/dist/conversation/session-actions.js +1 -1
  255. package/dist/conversation/subagent-sessions.js +1 -1
  256. package/dist/conversation/types.d.ts +6 -1
  257. package/dist/image-lightbox.js +1 -1
  258. package/dist/image-preview-dialog.js +1 -1
  259. package/dist/lib/code-highlighter.js +1 -1
  260. package/dist/lib/fuzzy.js +1 -1
  261. package/dist/lib/group-blocks.js +1 -1
  262. package/dist/lib/image-encode.js +1 -1
  263. package/dist/lib/limits.js +1 -1
  264. package/dist/lib/markdown-parser.js +1 -1
  265. package/dist/lib/markdown-rules.js +1 -1
  266. package/dist/lib/model-name.js +1 -1
  267. package/dist/lib/pointer-centered-zoom.js +1 -1
  268. package/dist/lib/prepare-prompt-files.js +1 -1
  269. package/dist/lib/stream-style.js +1 -1
  270. package/dist/lib/streaming-markdown.js +1 -1
  271. package/dist/locales.d.ts +1914 -0
  272. package/dist/locales.js +1 -1
  273. package/dist/plugins/catalog-header.d.ts +6 -0
  274. package/dist/plugins/catalog-header.js +1 -0
  275. package/dist/plugins/catalog-skeleton.d.ts +3 -0
  276. package/dist/plugins/catalog-skeleton.js +1 -0
  277. package/dist/plugins/host.d.ts +49 -0
  278. package/dist/plugins/host.js +1 -0
  279. package/dist/plugins/locales.d.ts +1136 -0
  280. package/dist/plugins/locales.js +1 -0
  281. package/dist/plugins/new-chat-directory.d.ts +2 -0
  282. package/dist/plugins/new-chat-directory.js +1 -0
  283. package/dist/plugins/pane.d.ts +12 -0
  284. package/dist/plugins/pane.js +1 -0
  285. package/dist/plugins/panel-item.d.ts +8 -0
  286. package/dist/plugins/panel-item.js +1 -0
  287. package/dist/plugins/plugin-detail-page.d.ts +5 -0
  288. package/dist/plugins/plugin-detail-page.js +1 -0
  289. package/dist/plugins/plugin-icon.d.ts +7 -0
  290. package/dist/plugins/plugin-icon.js +1 -0
  291. package/dist/plugins/plugin-icons.d.ts +1 -0
  292. package/dist/plugins/plugin-icons.js +1 -0
  293. package/dist/plugins/plugins-page.d.ts +12 -0
  294. package/dist/plugins/plugins-page.js +1 -0
  295. package/dist/plugins/plugins.css +199 -0
  296. package/dist/plugins/plugins.d.ts +14 -0
  297. package/dist/plugins/plugins.js +1 -0
  298. package/dist/plugins/read-skill-document.d.ts +2 -0
  299. package/dist/plugins/read-skill-document.js +1 -0
  300. package/dist/plugins/skill-document.d.ts +7 -0
  301. package/dist/plugins/skill-document.js +1 -0
  302. package/dist/plugins/skills-tab.d.ts +6 -0
  303. package/dist/plugins/skills-tab.js +1 -0
  304. package/dist/plugins/store.d.ts +62 -0
  305. package/dist/plugins/store.js +1 -0
  306. package/dist/plugins/toolbox-layout.d.ts +7 -0
  307. package/dist/plugins/toolbox-layout.js +1 -0
  308. package/dist/search/chat-search.css +9 -0
  309. package/dist/search/chat-search.d.ts +1 -0
  310. package/dist/search/chat-search.js +1 -1
  311. package/dist/search/codex-source-matches.d.ts +4 -0
  312. package/dist/search/codex-source-matches.js +1 -0
  313. package/dist/search/dom-matches.js +1 -1
  314. package/dist/search/find-bar.js +1 -1
  315. package/dist/search/literal-matches.js +1 -1
  316. package/dist/session-list/account-menu.d.ts +26 -0
  317. package/dist/session-list/account-menu.js +1 -0
  318. package/dist/session-list/activity-list.d.ts +11 -0
  319. package/dist/session-list/activity-list.js +1 -0
  320. package/dist/session-list/archived-sessions.js +1 -1
  321. package/dist/session-list/help-menu.d.ts +5 -0
  322. package/dist/session-list/help-menu.js +1 -0
  323. package/dist/session-list/highlight.js +1 -1
  324. package/dist/session-list/host.d.ts +2 -0
  325. package/dist/session-list/host.js +1 -1
  326. package/dist/session-list/hover-info-card.js +1 -1
  327. package/dist/session-list/locales.d.ts +91 -0
  328. package/dist/session-list/locales.js +1 -1
  329. package/dist/session-list/navigation-header.d.ts +14 -0
  330. package/dist/session-list/navigation-header.js +1 -0
  331. package/dist/session-list/navigation-store.d.ts +19 -0
  332. package/dist/session-list/navigation-store.js +1 -0
  333. package/dist/session-list/navigation-tabs.d.ts +20 -0
  334. package/dist/session-list/navigation-tabs.js +1 -0
  335. package/dist/session-list/navigation.js +1 -1
  336. package/dist/session-list/overflow-marquee.js +1 -1
  337. package/dist/session-list/platform.d.ts +2 -0
  338. package/dist/session-list/platform.js +1 -0
  339. package/dist/session-list/row-stop-button.js +1 -1
  340. package/dist/session-list/session-groups.js +1 -1
  341. package/dist/session-list/session-info-card.js +1 -1
  342. package/dist/session-list/session-list.d.ts +10 -0
  343. package/dist/session-list/session-list.js +1 -1
  344. package/dist/session-list/session-row.js +1 -1
  345. package/dist/session-list/session-state-dot.js +1 -1
  346. package/dist/session-list/session-state-menu.js +1 -1
  347. package/dist/session-list/shortcut-hint.d.ts +14 -0
  348. package/dist/session-list/shortcut-hint.js +1 -0
  349. package/dist/session-list/shortcut.d.ts +2 -0
  350. package/dist/session-list/shortcut.js +1 -0
  351. package/dist/session-list/sidebar-overlay.js +1 -1
  352. package/dist/session-list/trailing-swap.js +1 -1
  353. package/dist/session-list/use-activity-notification.d.ts +1 -0
  354. package/dist/session-list/use-activity-notification.js +1 -0
  355. package/dist/session-list/use-activity-preview.js +1 -1
  356. package/dist/session-list/use-cmd-held.d.ts +1 -0
  357. package/dist/session-list/use-cmd-held.js +1 -0
  358. package/dist/session-list/use-project-sessions.js +1 -1
  359. package/dist/session-list/virtual-session-rows.js +1 -1
  360. package/dist/session-timeline/activity-group.js +1 -1
  361. package/dist/session-timeline/activity-projection.js +1 -1
  362. package/dist/session-timeline/assistant-content.js +1 -1
  363. package/dist/session-timeline/assistant-turn.js +1 -1
  364. package/dist/session-timeline/async-questions.js +1 -1
  365. package/dist/session-timeline/edited-files-card.js +1 -1
  366. package/dist/session-timeline/history-timeline.js +1 -1
  367. package/dist/session-timeline/host.js +1 -1
  368. package/dist/session-timeline/navigation-rail.js +1 -1
  369. package/dist/session-timeline/plan.js +1 -1
  370. package/dist/session-timeline/question-reply.js +1 -1
  371. package/dist/session-timeline/resource-content.js +1 -1
  372. package/dist/session-timeline/session-timeline.js +1 -1
  373. package/dist/session-timeline/timeline-registry.js +1 -1
  374. package/dist/session-timeline/turn-activity.js +1 -1
  375. package/dist/session-timeline/turn-error.js +1 -1
  376. package/dist/session-timeline/turn-retry.js +1 -1
  377. package/dist/session-timeline/turn-time.js +1 -1
  378. package/dist/session-timeline/turns.js +1 -1
  379. package/dist/session-timeline/use-timeline-scroll.js +1 -1
  380. package/dist/session-timeline/user-message.js +1 -1
  381. package/dist/settings/codex-account-card.d.ts +18 -0
  382. package/dist/settings/codex-account-card.js +1 -0
  383. package/dist/settings/login-card.d.ts +6 -0
  384. package/dist/settings/login-card.js +1 -0
  385. package/dist/settings/model-alias-settings.d.ts +6 -0
  386. package/dist/settings/model-alias-settings.js +1 -0
  387. package/dist/settings/model-aliases.d.ts +17 -0
  388. package/dist/settings/model-aliases.js +1 -0
  389. package/dist/settings/provider-logos.d.ts +5 -0
  390. package/dist/settings/provider-logos.js +1 -0
  391. package/dist/settings/provider-section.d.ts +52 -0
  392. package/dist/settings/provider-section.js +1 -0
  393. package/dist/settings/providers-port.d.ts +32 -0
  394. package/dist/settings/providers-port.js +1 -0
  395. package/dist/settings/providers.d.ts +92 -0
  396. package/dist/settings/providers.js +1 -0
  397. package/dist/settings/settings-bridge.d.ts +39 -0
  398. package/dist/settings/settings-bridge.js +1 -0
  399. package/dist/settings/settings.d.ts +9 -0
  400. package/dist/settings/settings.js +1 -0
  401. package/dist/stage.d.ts +1 -0
  402. package/dist/stage.js +1 -1
  403. package/emojibase/LICENSE +21 -0
  404. package/emojibase/en/data.json +51183 -0
  405. package/emojibase/en/messages.json +124 -0
  406. package/emojibase/zh/data.json +48992 -0
  407. package/emojibase/zh/messages.json +124 -0
  408. package/licenses/_dnd-kit_core-LICENSE +21 -0
  409. package/licenses/_dnd-kit_sortable-LICENSE +21 -0
  410. package/licenses/_dnd-kit_utilities-LICENSE +21 -0
  411. package/licenses/_solar-icons_react-LICENSE +11 -0
  412. package/licenses/_solar-icons_react-LICENSE-THIRD-PARTY +14 -0
  413. package/licenses/frimousse-LICENSE +21 -0
  414. package/package.json +41 -7
  415. package/rust/Cargo.lock +3844 -0
  416. package/rust/Cargo.toml +29 -0
  417. package/rust/build.rs +16 -0
  418. package/rust/permissions/autogenerated/reference.md +296 -0
  419. package/rust/permissions/default.toml +20 -0
  420. package/rust/permissions/schemas/schema.json +292 -0
  421. package/rust/src/lib.rs +79 -0
  422. package/rust/src/providers/managed.rs +801 -0
  423. package/rust/src/providers/tests.rs +681 -0
  424. package/rust/src/providers.rs +984 -0
  425. package/rust/src/skills.rs +130 -0
  426. package/dist/chunk-074x98ak.js +0 -2
  427. package/dist/chunk-0c8fy456.js +0 -4
  428. package/dist/chunk-0dnwqm94.js +0 -2
  429. package/dist/chunk-0nkvfecf.js +0 -1
  430. package/dist/chunk-0ss92kxr.js +0 -2
  431. package/dist/chunk-12fcr66z.js +0 -2
  432. package/dist/chunk-14r2ktqe.js +0 -3
  433. package/dist/chunk-180zvfd6.js +0 -2
  434. package/dist/chunk-1fm5vx1n.js +0 -1
  435. package/dist/chunk-2a3tezgr.js +0 -1
  436. package/dist/chunk-2rperg04.js +0 -1
  437. package/dist/chunk-3919sqde.js +0 -2
  438. package/dist/chunk-3dckftt6.js +0 -2
  439. package/dist/chunk-3k5n3809.js +0 -2
  440. package/dist/chunk-3z6rx5qv.js +0 -4
  441. package/dist/chunk-4s1rhts0.js +0 -1
  442. package/dist/chunk-58wt406v.js +0 -1
  443. package/dist/chunk-59g9h4v1.js +0 -2
  444. package/dist/chunk-59j0p8hy.js +0 -2
  445. package/dist/chunk-6s7z09b0.js +0 -2
  446. package/dist/chunk-6t3tgzps.js +0 -2
  447. package/dist/chunk-6wqbetcx.js +0 -1
  448. package/dist/chunk-75zcgcqm.js +0 -2
  449. package/dist/chunk-7ap638hx.js +0 -2
  450. package/dist/chunk-7jdjdnh6.js +0 -2
  451. package/dist/chunk-7wyrcphh.js +0 -1
  452. package/dist/chunk-83sz9mv9.js +0 -3
  453. package/dist/chunk-88cfz41t.js +0 -2
  454. package/dist/chunk-8bfnjqkg.js +0 -2
  455. package/dist/chunk-8g09jrj1.js +0 -2
  456. package/dist/chunk-8v1bjdgv.js +0 -2
  457. package/dist/chunk-90wm9rxz.js +0 -2
  458. package/dist/chunk-91h14q3y.js +0 -2
  459. package/dist/chunk-96x0d2vd.js +0 -1
  460. package/dist/chunk-9gv1zffv.js +0 -1
  461. package/dist/chunk-9j609g4n.js +0 -1
  462. package/dist/chunk-afd3bq7v.js +0 -2
  463. package/dist/chunk-bew4srqj.js +0 -2
  464. package/dist/chunk-bj5ma2sv.js +0 -2
  465. package/dist/chunk-bv4adcrd.js +0 -2
  466. package/dist/chunk-c1vavp0q.js +0 -2
  467. package/dist/chunk-c26vy827.js +0 -2
  468. package/dist/chunk-cc0tan75.js +0 -2
  469. package/dist/chunk-d5ga13n0.js +0 -1
  470. package/dist/chunk-d94rmh12.js +0 -2
  471. package/dist/chunk-da4m33bg.js +0 -2
  472. package/dist/chunk-da6d6wze.js +0 -1
  473. package/dist/chunk-e99sdapw.js +0 -2
  474. package/dist/chunk-ea3582qy.js +0 -1
  475. package/dist/chunk-ebmbz9tg.js +0 -2
  476. package/dist/chunk-frbeen15.js +0 -2
  477. package/dist/chunk-ftcydsbs.js +0 -2
  478. package/dist/chunk-gdpa9dp5.js +0 -1
  479. package/dist/chunk-gz7adphb.js +0 -2
  480. package/dist/chunk-gzeg6bqp.js +0 -2
  481. package/dist/chunk-h68f23r0.js +0 -1
  482. package/dist/chunk-h99fy0g3.js +0 -4
  483. package/dist/chunk-jdjk6tf4.js +0 -1
  484. package/dist/chunk-jjnmq2zj.js +0 -3
  485. package/dist/chunk-khj3ye94.js +0 -7
  486. package/dist/chunk-kjtd3wc3.js +0 -1
  487. package/dist/chunk-kmhwwzga.js +0 -2
  488. package/dist/chunk-mr1azhef.js +0 -1
  489. package/dist/chunk-n0xzhjdg.js +0 -2
  490. package/dist/chunk-n1tjf64a.js +0 -2
  491. package/dist/chunk-n5xqjct2.js +0 -1
  492. package/dist/chunk-nqv69z6n.js +0 -2
  493. package/dist/chunk-pv35kspb.js +0 -1
  494. package/dist/chunk-pw6p654f.js +0 -3
  495. package/dist/chunk-q6km9nha.js +0 -2
  496. package/dist/chunk-qca5mhqd.js +0 -2
  497. package/dist/chunk-qxabrz98.js +0 -2
  498. package/dist/chunk-r1988zpy.js +0 -2
  499. package/dist/chunk-s0ef3h7b.js +0 -2
  500. package/dist/chunk-sespfp7t.js +0 -4
  501. package/dist/chunk-sf6ze845.js +0 -2
  502. package/dist/chunk-sxgc25gz.js +0 -2
  503. package/dist/chunk-tq6ekz3s.js +0 -2
  504. package/dist/chunk-vp8fb7r8.js +0 -2
  505. package/dist/chunk-w1awbykg.js +0 -2
  506. package/dist/chunk-wpdn3rx8.js +0 -1
  507. package/dist/chunk-x1xh8y2s.js +0 -2
  508. package/dist/chunk-x8kxqtva.js +0 -2
  509. package/dist/chunk-xfx689xm.js +0 -3
  510. package/dist/chunk-y6afvrnv.js +0 -2
  511. package/dist/chunk-zb4mqy8f.js +0 -2
  512. package/dist/ui/alert.d.ts +0 -10
  513. package/dist/ui/alert.js +0 -1
  514. package/dist/ui/badge.d.ts +0 -7
  515. package/dist/ui/badge.js +0 -1
  516. package/dist/ui/button.d.ts +0 -8
  517. package/dist/ui/button.js +0 -1
  518. package/dist/ui/card.d.ts +0 -11
  519. package/dist/ui/card.js +0 -1
  520. package/dist/ui/checkbox.d.ts +0 -3
  521. package/dist/ui/checkbox.js +0 -1
  522. package/dist/ui/dialog.d.ts +0 -17
  523. package/dist/ui/dialog.js +0 -1
  524. package/dist/ui/dropdown-menu.d.ts +0 -29
  525. package/dist/ui/dropdown-menu.js +0 -1
  526. package/dist/ui/empty.d.ts +0 -11
  527. package/dist/ui/empty.js +0 -1
  528. package/dist/ui/field.d.ts +0 -24
  529. package/dist/ui/field.js +0 -1
  530. package/dist/ui/hover-card.d.ts +0 -5
  531. package/dist/ui/hover-card.js +0 -1
  532. package/dist/ui/input-group.d.ts +0 -18
  533. package/dist/ui/input-group.js +0 -1
  534. package/dist/ui/input.d.ts +0 -3
  535. package/dist/ui/input.js +0 -1
  536. package/dist/ui/kbd.d.ts +0 -3
  537. package/dist/ui/kbd.js +0 -1
  538. package/dist/ui/label.d.ts +0 -3
  539. package/dist/ui/label.js +0 -1
  540. package/dist/ui/radio-group.d.ts +0 -5
  541. package/dist/ui/radio-group.js +0 -1
  542. package/dist/ui/select.d.ts +0 -15
  543. package/dist/ui/select.js +0 -1
  544. package/dist/ui/separator.d.ts +0 -3
  545. package/dist/ui/separator.js +0 -1
  546. package/dist/ui/skeleton.d.ts +0 -2
  547. package/dist/ui/skeleton.js +0 -1
  548. package/dist/ui/spinner.d.ts +0 -2
  549. package/dist/ui/spinner.js +0 -1
  550. package/dist/ui/switch.d.ts +0 -5
  551. package/dist/ui/switch.js +0 -1
  552. package/dist/ui/textarea.d.ts +0 -3
  553. package/dist/ui/textarea.js +0 -1
  554. package/dist/ui/tooltip.d.ts +0 -6
  555. package/dist/ui/tooltip.js +0 -1
@@ -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
+ }