@cortexkit/opencode-openai-auth 0.11.1 → 1.0.0

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 (204) hide show
  1. package/README.md +15 -26
  2. package/dist/index-766sfrh5.js +1 -0
  3. package/dist/index-8kj7sa1p.js +12 -0
  4. package/dist/index-8rqfbhfw.js +221 -0
  5. package/dist/index-b3q3j39x.js +2 -0
  6. package/dist/index-bmd7x5aq.js +2 -0
  7. package/dist/index-eqh53k8v.js +2 -0
  8. package/dist/{index-sdt2d2ra.js → index-hy9030jh.js} +1 -1
  9. package/dist/index-jyr8y8k4.js +7 -0
  10. package/dist/index-rv08jmd4.js +2 -0
  11. package/dist/index.d.ts +578 -145
  12. package/dist/index.js +1 -110
  13. package/dist/pool-lifecycle-DbDmgabd.d.ts +2430 -0
  14. package/dist/port-file-Do3lQIEk.d.ts +29 -0
  15. package/dist/protocol-BOBdkqqm.d.ts +198 -0
  16. package/dist/rpc/port-file.d.ts +4 -17
  17. package/dist/rpc/port-file.js +1 -1
  18. package/dist/rpc/protocol.d.ts +2 -2
  19. package/dist/rpc/protocol.js +1 -0
  20. package/dist/rpc/rpc-client.d.ts +5 -4
  21. package/dist/rpc/rpc-client.js +1 -1
  22. package/dist/rpc/rpc-dir.d.ts +2 -0
  23. package/dist/rpc/rpc-dir.js +1 -1
  24. package/dist/sidebar-state-D6cUKgkm.d.ts +385 -0
  25. package/dist/sidebar-state.d.ts +2 -2
  26. package/dist/sidebar-state.js +1 -1
  27. package/dist/token-util-wdza526f.js +1 -0
  28. package/dist/{token-9823y0pc.js → token-ypk61xj0.js} +1 -1
  29. package/dist/tui-preferences.js +5 -2
  30. package/dist/tui.d.ts +9 -4
  31. package/dist/v2/server.d.ts +54 -0
  32. package/dist/v2/server.js +4 -0
  33. package/package.json +21 -9
  34. package/src/tui/entry.mjs +26 -25
  35. package/src/tui-compiled/raw/logger.js +24 -0
  36. package/src/tui-compiled/raw/rpc/protocol.js +3 -0
  37. package/src/tui-compiled/raw/rpc/rpc-client.js +7 -0
  38. package/src/tui-compiled/raw/rpc/rpc-dir.js +27 -0
  39. package/src/tui-compiled/raw/selector.js +21 -0
  40. package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +138 -0
  41. package/src/tui-compiled/raw/shared/04a6357627de5ed0-errors.js +38 -0
  42. package/src/tui-compiled/raw/shared/053cc17b5419261e-codec.js +12 -0
  43. package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +157 -0
  44. package/src/tui-compiled/raw/shared/08eef45626a94992-reserved.js +13 -0
  45. package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +134 -0
  46. package/src/tui-compiled/raw/shared/3c2d4169d00f907e-tui-support.js +5 -0
  47. package/src/tui-compiled/raw/shared/3e7d45a77c6ad4d5-index.js +4 -0
  48. package/src/tui-compiled/raw/shared/415792e85d80819e-capture-sink.js +13 -0
  49. package/src/tui-compiled/raw/shared/42ae93ab554fcec2-open-url.js +28 -0
  50. package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
  51. package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +500 -0
  52. package/src/tui-compiled/raw/shared/45bf5343bbbf9add-admission.js +142 -0
  53. package/src/tui-compiled/raw/shared/46f3dff1266160e8-client.js +2 -0
  54. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +48 -0
  55. package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +162 -0
  56. package/src/tui-compiled/raw/shared/54eba94fd64c8c3c-index.js +7 -0
  57. package/src/tui-compiled/raw/shared/7211cfec06a298bc-atomic-write.js +80 -0
  58. package/src/tui-compiled/raw/shared/754d6017f8e419cf-builtins.js +534 -0
  59. package/src/tui-compiled/raw/shared/75bd8c3bd63b315f-identity.js +79 -0
  60. package/src/tui-compiled/raw/shared/7a91bb630e6f4804-index.js +1 -0
  61. package/src/tui-compiled/raw/shared/826342a4b6a8b89b-model.js +16 -0
  62. package/src/tui-compiled/raw/shared/83068c0dbe8a6f13-publication.js +304 -0
  63. package/src/tui-compiled/raw/shared/836fc615de6afbd9-settings.js +120 -0
  64. package/src/tui-compiled/raw/shared/83bc3ba9d0fe2761-runtime.js +68 -0
  65. package/src/tui-compiled/raw/shared/8a18abe4fa2977c8-menu.js +300 -0
  66. package/src/tui-compiled/raw/shared/901e149c5a0dbbff-sticky.js +339 -0
  67. package/src/tui-compiled/raw/shared/9020c407ce64f672-ordered.js +58 -0
  68. package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +105 -0
  69. package/src/tui-compiled/raw/shared/94820e324f2b4c09-seam.js +301 -0
  70. package/src/tui-compiled/raw/shared/97484d9bb98c705b-provider-state.js +226 -0
  71. package/src/tui-compiled/raw/shared/9968e3cade6969a1-index.js +2 -0
  72. package/src/tui-compiled/raw/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
  73. package/src/tui-compiled/raw/shared/9d3fc9e37456504e-refresh.js +225 -0
  74. package/src/tui-compiled/raw/shared/9deae3c4da4fd63b-hooks.js +34 -0
  75. package/src/tui-compiled/raw/shared/a09b6a533c11858f-tui-preferences.js +77 -0
  76. package/src/tui-compiled/raw/shared/a62a27a204266acd-attribution.js +60 -0
  77. package/src/tui-compiled/raw/shared/a910277ac43a8626-pull.js +143 -0
  78. package/src/tui-compiled/raw/shared/b85c5301fddcb98a-paths.js +5 -0
  79. package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +217 -0
  80. package/src/tui-compiled/raw/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
  81. package/src/tui-compiled/raw/shared/c6b176708c446d6d-pins.js +34 -0
  82. package/src/tui-compiled/raw/shared/c7d252bedee01600-pi.js +206 -0
  83. package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +120 -0
  84. package/src/tui-compiled/raw/shared/cc9e0702a752cea7-index.js +3 -0
  85. package/src/tui-compiled/raw/shared/cd94316a888b0a8e-schema.js +754 -0
  86. package/src/tui-compiled/raw/shared/d319517e3ea6ad70-redact.js +83 -0
  87. package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +5 -0
  88. package/src/tui-compiled/raw/shared/d669d72c40e9e116-logger.js +19 -0
  89. package/src/tui-compiled/raw/shared/d7dcba96fea1685c-engine.js +246 -0
  90. package/src/tui-compiled/raw/shared/dbef697d1df1cd84-index.js +5 -0
  91. package/src/tui-compiled/raw/shared/e4acc4cb713f300c-protocol.js +3 -0
  92. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
  93. package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +6 -0
  94. package/src/tui-compiled/raw/shared/f37fcefc7aedbf25-error.js +11 -0
  95. package/src/tui-compiled/raw/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
  96. package/src/tui-compiled/raw/shared/fd45e82f2f9c0a0d-torn.js +294 -0
  97. package/src/tui-compiled/raw/shared/fe02abeadc535f77-rows.js +1258 -0
  98. package/src/tui-compiled/raw/sidebar-state.js +960 -0
  99. package/src/tui-compiled/raw/tui/command-dialogs.tsx +424 -0
  100. package/src/tui-compiled/raw/tui-preferences.js +135 -0
  101. package/src/tui-compiled/raw/tui.tsx +135 -143
  102. package/src/tui-compiled/runtime/logger.js +24 -0
  103. package/src/tui-compiled/runtime/rpc/protocol.js +3 -0
  104. package/src/tui-compiled/runtime/rpc/rpc-client.js +7 -0
  105. package/src/tui-compiled/runtime/rpc/rpc-dir.js +27 -0
  106. package/src/tui-compiled/runtime/selector.js +21 -0
  107. package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +138 -0
  108. package/src/tui-compiled/runtime/shared/04a6357627de5ed0-errors.js +38 -0
  109. package/src/tui-compiled/runtime/shared/053cc17b5419261e-codec.js +12 -0
  110. package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +157 -0
  111. package/src/tui-compiled/runtime/shared/08eef45626a94992-reserved.js +13 -0
  112. package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +134 -0
  113. package/src/tui-compiled/runtime/shared/3c2d4169d00f907e-tui-support.js +5 -0
  114. package/src/tui-compiled/runtime/shared/3e7d45a77c6ad4d5-index.js +4 -0
  115. package/src/tui-compiled/runtime/shared/415792e85d80819e-capture-sink.js +13 -0
  116. package/src/tui-compiled/runtime/shared/42ae93ab554fcec2-open-url.js +28 -0
  117. package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +136 -0
  118. package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +500 -0
  119. package/src/tui-compiled/runtime/shared/45bf5343bbbf9add-admission.js +142 -0
  120. package/src/tui-compiled/runtime/shared/46f3dff1266160e8-client.js +2 -0
  121. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +48 -0
  122. package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +162 -0
  123. package/src/tui-compiled/runtime/shared/54eba94fd64c8c3c-index.js +7 -0
  124. package/src/tui-compiled/runtime/shared/7211cfec06a298bc-atomic-write.js +80 -0
  125. package/src/tui-compiled/runtime/shared/754d6017f8e419cf-builtins.js +534 -0
  126. package/src/tui-compiled/runtime/shared/75bd8c3bd63b315f-identity.js +79 -0
  127. package/src/tui-compiled/runtime/shared/7a91bb630e6f4804-index.js +1 -0
  128. package/src/tui-compiled/runtime/shared/826342a4b6a8b89b-model.js +16 -0
  129. package/src/tui-compiled/runtime/shared/83068c0dbe8a6f13-publication.js +304 -0
  130. package/src/tui-compiled/runtime/shared/836fc615de6afbd9-settings.js +120 -0
  131. package/src/tui-compiled/runtime/shared/83bc3ba9d0fe2761-runtime.js +68 -0
  132. package/src/tui-compiled/runtime/shared/8a18abe4fa2977c8-menu.js +300 -0
  133. package/src/tui-compiled/runtime/shared/901e149c5a0dbbff-sticky.js +339 -0
  134. package/src/tui-compiled/runtime/shared/9020c407ce64f672-ordered.js +58 -0
  135. package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +105 -0
  136. package/src/tui-compiled/runtime/shared/94820e324f2b4c09-seam.js +301 -0
  137. package/src/tui-compiled/runtime/shared/97484d9bb98c705b-provider-state.js +226 -0
  138. package/src/tui-compiled/runtime/shared/9968e3cade6969a1-index.js +2 -0
  139. package/src/tui-compiled/runtime/shared/9b4da614c45f9cd0-lock-constants.js +14 -0
  140. package/src/tui-compiled/runtime/shared/9d3fc9e37456504e-refresh.js +225 -0
  141. package/src/tui-compiled/runtime/shared/9deae3c4da4fd63b-hooks.js +34 -0
  142. package/src/tui-compiled/runtime/shared/a09b6a533c11858f-tui-preferences.js +77 -0
  143. package/src/tui-compiled/runtime/shared/a62a27a204266acd-attribution.js +60 -0
  144. package/src/tui-compiled/runtime/shared/a910277ac43a8626-pull.js +143 -0
  145. package/src/tui-compiled/runtime/shared/b85c5301fddcb98a-paths.js +5 -0
  146. package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +217 -0
  147. package/src/tui-compiled/runtime/shared/c64d7afbc14ca125-sidebar-file.js +157 -0
  148. package/src/tui-compiled/runtime/shared/c6b176708c446d6d-pins.js +34 -0
  149. package/src/tui-compiled/runtime/shared/c7d252bedee01600-pi.js +206 -0
  150. package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +120 -0
  151. package/src/tui-compiled/runtime/shared/cc9e0702a752cea7-index.js +3 -0
  152. package/src/tui-compiled/runtime/shared/cd94316a888b0a8e-schema.js +754 -0
  153. package/src/tui-compiled/runtime/shared/d319517e3ea6ad70-redact.js +83 -0
  154. package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +5 -0
  155. package/src/tui-compiled/runtime/shared/d669d72c40e9e116-logger.js +19 -0
  156. package/src/tui-compiled/runtime/shared/d7dcba96fea1685c-engine.js +246 -0
  157. package/src/tui-compiled/runtime/shared/dbef697d1df1cd84-index.js +5 -0
  158. package/src/tui-compiled/runtime/shared/e4acc4cb713f300c-protocol.js +3 -0
  159. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +501 -0
  160. package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +6 -0
  161. package/src/tui-compiled/runtime/shared/f37fcefc7aedbf25-error.js +11 -0
  162. package/src/tui-compiled/runtime/shared/fbcdcd0f925e74c0-rpc-client.js +253 -0
  163. package/src/tui-compiled/runtime/shared/fd45e82f2f9c0a0d-torn.js +294 -0
  164. package/src/tui-compiled/runtime/shared/fe02abeadc535f77-rows.js +1258 -0
  165. package/src/tui-compiled/runtime/sidebar-state.js +960 -0
  166. package/src/tui-compiled/runtime/tui/command-dialogs.js +378 -0
  167. package/src/tui-compiled/runtime/tui-preferences.js +135 -0
  168. package/src/tui-compiled/runtime/{tui.tsx → tui.js} +288 -316
  169. package/dist/index-4effjmr6.js +0 -2
  170. package/dist/index-9ehhb051.js +0 -2
  171. package/dist/index-g3hsdjh4.js +0 -2
  172. package/dist/index-hh52v8sb.js +0 -2
  173. package/dist/index-jwn4r3sw.js +0 -1
  174. package/dist/index-sq36b120.js +0 -211
  175. package/dist/internal-BTndPmW2.d.ts +0 -914
  176. package/dist/quota-normalize-08hpp51v.js +0 -1
  177. package/dist/sidebar-state-CoKYKcLn.d.ts +0 -220
  178. package/dist/token-util-ypgz7rge.js +0 -1
  179. package/src/tui-compiled/raw/core-account-paths.ts +0 -114
  180. package/src/tui-compiled/raw/core-custody-state.ts +0 -243
  181. package/src/tui-compiled/raw/logger.ts +0 -53
  182. package/src/tui-compiled/raw/rpc-port-file.ts +0 -177
  183. package/src/tui-compiled/raw/rpc-protocol.ts +0 -12
  184. package/src/tui-compiled/raw/rpc-rpc-client.ts +0 -82
  185. package/src/tui-compiled/raw/rpc-rpc-dir.ts +0 -46
  186. package/src/tui-compiled/raw/sidebar-state.ts +0 -1659
  187. package/src/tui-compiled/raw/tui-command-dialogs.tsx +0 -1096
  188. package/src/tui-compiled/raw/tui-preferences.ts +0 -328
  189. package/src/tui-compiled/runtime/core-account-paths.ts +0 -114
  190. package/src/tui-compiled/runtime/core-custody-state.ts +0 -243
  191. package/src/tui-compiled/runtime/logger.ts +0 -53
  192. package/src/tui-compiled/runtime/rpc-port-file.ts +0 -177
  193. package/src/tui-compiled/runtime/rpc-protocol.ts +0 -12
  194. package/src/tui-compiled/runtime/rpc-rpc-client.ts +0 -82
  195. package/src/tui-compiled/runtime/rpc-rpc-dir.ts +0 -46
  196. package/src/tui-compiled/runtime/sidebar-state.ts +0 -1659
  197. package/src/tui-compiled/runtime/tui-command-dialogs.tsx +0 -855
  198. package/src/tui-compiled/runtime/tui-preferences.ts +0 -328
  199. package/src/tui-compiled/shared/internal.ts +0 -6
  200. package/src/tui-compiled/shared/logger.ts +0 -264
  201. package/src/tui-compiled/shared/paths.ts +0 -33
  202. package/src/tui-compiled/shared/refresh-file-lock.ts +0 -384
  203. package/src/tui-compiled/shared/util/error.ts +0 -9
  204. package/src/tui-compiled/shared/util/open-url.ts +0 -30
@@ -0,0 +1,378 @@
1
+ import { insertNode as _$insertNode } from "opentui:runtime-module:%40opentui%2Fsolid";
2
+ import { insert as _$insert } from "opentui:runtime-module:%40opentui%2Fsolid";
3
+ import { setProp as _$setProp } from "opentui:runtime-module:%40opentui%2Fsolid";
4
+ import { createElement as _$createElement } from "opentui:runtime-module:%40opentui%2Fsolid";
5
+ import { memo as _$memo } from "opentui:runtime-module:%40opentui%2Fsolid";
6
+ import { createComponent as _$createComponent } from "opentui:runtime-module:%40opentui%2Fsolid";
7
+ /** @jsxImportSource @opentui/solid */
8
+
9
+ // The `/openai` drawer: one generic renderer for the shared command menu's
10
+ // payload. The payload carries everything drawn here (sections with their
11
+ // lines, items, facts and actions; each action's typed inputs with their
12
+ // current values and its confirmation), so the drawer knows nothing about
13
+ // any one section. After every apply it redraws from the refreshed menu the
14
+ // result carries.
15
+
16
+ import { createLogger } from "../logger.js";
17
+ const log = createLogger('rpc-tui');
18
+
19
+ /** Sends one action to the plugin; the session id is added by the caller. */
20
+
21
+ const BACK = 'back';
22
+
23
+ /** One option per section, in the order the menu gives them. */
24
+ export function sectionListOptions(menu) {
25
+ return menu.sections.map(section => ({
26
+ title: section.title,
27
+ value: `section:${section.id}`,
28
+ ...(section.lines[0] ? {
29
+ description: section.lines[0]
30
+ } : {})
31
+ }));
32
+ }
33
+ function factLines(facts) {
34
+ return Object.entries(facts ?? {}).map(([name, value]) => `${name}: ${typeof value === 'string' ? value : JSON.stringify(value)}`);
35
+ }
36
+
37
+ /** Read-only text is a category header; every option navigates or runs an action. */
38
+ export function sectionOptions(section) {
39
+ const header = [...section.lines, ...factLines(section.facts), ...section.items.filter(item => item.actions.length === 0).map(item => [item.group, [item.label, item.status].filter(Boolean).join(' · '), item.detail, ...factLines(item.facts)].filter(Boolean).join('\n'))];
40
+ const options = [...section.items.filter(item => item.actions.length > 0).map(item => ({
41
+ title: item.label,
42
+ value: `item:${item.id}`,
43
+ ...(item.detail ? {
44
+ description: item.detail
45
+ } : {}),
46
+ ...(item.group ? {
47
+ category: item.group
48
+ } : {}),
49
+ ...(item.status ? {
50
+ footer: item.status
51
+ } : {})
52
+ })), ...section.actions.map(action => ({
53
+ title: action.label,
54
+ value: `action:${action.id}`,
55
+ ...(action.description ? {
56
+ description: action.description
57
+ } : {}),
58
+ ...(action.group ? {
59
+ category: action.group
60
+ } : {})
61
+ })), {
62
+ title: 'Back',
63
+ value: BACK
64
+ }];
65
+ const first = options[0];
66
+ if (first && header.length > 0) {
67
+ const category = first.category;
68
+ const text = [...header, category].filter(Boolean).join('\n');
69
+ for (const option of options) {
70
+ if (option.category !== category) break;
71
+ option.category = text;
72
+ }
73
+ }
74
+ return options;
75
+ }
76
+
77
+ /** Item context is secondary text, never an option that cannot be acted on. */
78
+ export function itemOptions(item) {
79
+ const detail = [item.detail, ...factLines(item.facts)].filter(Boolean).join(' · ');
80
+ return [...item.actions.map(action => ({
81
+ title: action.label,
82
+ value: `action:${action.id}`,
83
+ ...(detail || action.description ? {
84
+ description: [detail, action.description].filter(Boolean).join(' · ')
85
+ } : {}),
86
+ ...(action.group ? {
87
+ category: action.group
88
+ } : {})
89
+ })), {
90
+ title: 'Back',
91
+ value: BACK
92
+ }];
93
+ }
94
+
95
+ /**
96
+ * The value a typed `number` or `text` input sends: empty is `null` (the
97
+ * action receives that as "leave unset"), a number input sends a number
98
+ * when the text parses as one and the text otherwise, so the plugin can say
99
+ * what is wrong with it.
100
+ */
101
+ export function promptValue(knob, raw) {
102
+ const text = raw.trim();
103
+ if (text === '') return null;
104
+ if (knob.kind === 'number') {
105
+ const number = Number(text);
106
+ return Number.isFinite(number) ? number : text;
107
+ }
108
+ return raw;
109
+ }
110
+ function knobDefault(knob) {
111
+ if (knob.kind === 'toggle') return knob.value ? 'on' : 'off';
112
+ return knob.value === undefined ? '' : String(knob.value);
113
+ }
114
+ /** Opens the drawer on a payload pushed by `/openai`. */
115
+ export function openCommandDialog(api, payload, apply) {
116
+ showMenu({
117
+ api,
118
+ apply
119
+ }, payload.command, payload.menu);
120
+ }
121
+ function showMenu(context, command, menu) {
122
+ const {
123
+ api
124
+ } = context;
125
+ // A menu with one section (the not-migrated notice) opens on it directly.
126
+ if (menu.sections.length === 1) {
127
+ const [only] = menu.sections;
128
+ if (only) {
129
+ showSection(context, command, menu, only.id);
130
+ return;
131
+ }
132
+ }
133
+ const DialogSelect = api.ui.DialogSelect;
134
+ api.ui.dialog.setSize('xlarge');
135
+ api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
136
+ get title() {
137
+ return menu.title;
138
+ },
139
+ get options() {
140
+ return sectionListOptions(menu);
141
+ },
142
+ onSelect: option => {
143
+ const id = String(option.value).slice('section:'.length);
144
+ showSection(context, command, menu, id);
145
+ }
146
+ }));
147
+ }
148
+ function showSection(context, command, menu, sectionId) {
149
+ const {
150
+ api
151
+ } = context;
152
+ const section = menu.sections.find(entry => entry.id === sectionId);
153
+ if (!section) {
154
+ showMenu(context, command, menu);
155
+ return;
156
+ }
157
+ const DialogSelect = api.ui.DialogSelect;
158
+ api.ui.dialog.setSize('xlarge');
159
+ api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
160
+ get title() {
161
+ return section.title;
162
+ },
163
+ get options() {
164
+ return sectionOptions(section);
165
+ },
166
+ onSelect: option => {
167
+ const value = String(option.value);
168
+ if (value === BACK) {
169
+ if (menu.sections.length === 1) api.ui.dialog.clear();else showMenu(context, command, menu);
170
+ return;
171
+ }
172
+ if (value.startsWith('item:')) {
173
+ showItem(context, command, menu, section, value.slice(5));
174
+ return;
175
+ }
176
+ if (value.startsWith('action:')) {
177
+ const action = section.actions.find(entry => entry.id === value.slice(7));
178
+ if (action) void runAction(context, command, menu, section, undefined, action);
179
+ }
180
+ }
181
+ }));
182
+ }
183
+ function showItem(context, command, menu, section, itemId) {
184
+ const {
185
+ api
186
+ } = context;
187
+ const item = section.items.find(entry => entry.id === itemId);
188
+ if (!item) {
189
+ showSection(context, command, menu, section.id);
190
+ return;
191
+ }
192
+ const DialogSelect = api.ui.DialogSelect;
193
+ api.ui.dialog.setSize('xlarge');
194
+ api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
195
+ get title() {
196
+ return `${section.title}: ${item.label}`;
197
+ },
198
+ get options() {
199
+ return itemOptions(item);
200
+ },
201
+ onSelect: option => {
202
+ const value = String(option.value);
203
+ if (value === BACK) {
204
+ showSection(context, command, menu, section.id);
205
+ return;
206
+ }
207
+ if (value.startsWith('action:')) {
208
+ const action = item.actions.find(entry => entry.id === value.slice(7));
209
+ if (action) void runAction(context, command, menu, section, item, action);
210
+ }
211
+ }
212
+ }));
213
+ }
214
+
215
+ /** Asks for one input; resolves undefined when the user backs out. */
216
+ function askKnob(api, title, knob) {
217
+ return new Promise(resolve => {
218
+ api.ui.dialog.setSize('xlarge');
219
+ if (knob.kind === 'choice' || knob.kind === 'toggle') {
220
+ const DialogSelect = api.ui.DialogSelect;
221
+ const options = knob.kind === 'choice' ? knob.choices.map(choice => ({
222
+ title: choice.label,
223
+ value: choice.value
224
+ })) : [{
225
+ title: 'On',
226
+ value: 'on'
227
+ }, {
228
+ title: 'Off',
229
+ value: 'off'
230
+ }];
231
+ api.ui.dialog.replace(() => _$createComponent(DialogSelect, {
232
+ get title() {
233
+ return `${title}: ${knob.label}`;
234
+ },
235
+ get current() {
236
+ return knobDefault(knob);
237
+ },
238
+ get options() {
239
+ return [...options, {
240
+ title: 'Cancel',
241
+ value: `\u0000cancel`
242
+ }];
243
+ },
244
+ onSelect: option => {
245
+ const value = String(option.value);
246
+ if (value === `\u0000cancel`) resolve(undefined);else resolve(knob.kind === 'toggle' ? value === 'on' : value);
247
+ }
248
+ }));
249
+ return;
250
+ }
251
+ const DialogPrompt = api.ui.DialogPrompt;
252
+ api.ui.dialog.replace(() => _$createComponent(DialogPrompt, {
253
+ get title() {
254
+ return `${title}: ${knob.label}`;
255
+ },
256
+ get placeholder() {
257
+ return _$memo(() => knob.kind === 'text')() ? knob.placeholder ?? '' : '';
258
+ },
259
+ get value() {
260
+ return knobDefault(knob);
261
+ },
262
+ onConfirm: value => resolve(promptValue(knob, value)),
263
+ onCancel: () => resolve(undefined)
264
+ }));
265
+ });
266
+ }
267
+ function askConfirmation(api, title, message) {
268
+ return new Promise(resolve => {
269
+ const DialogConfirm = api.ui.DialogConfirm;
270
+ api.ui.dialog.setSize('xlarge');
271
+ api.ui.dialog.replace(() => _$createComponent(DialogConfirm, {
272
+ title: title,
273
+ message: message,
274
+ onConfirm: () => resolve(true),
275
+ onCancel: () => resolve(false)
276
+ }));
277
+ });
278
+ }
279
+ function showResult(api, title, text) {
280
+ api.ui.dialog.setSize('xlarge');
281
+ api.ui.dialog.replace(() => (() => {
282
+ var _el$ = _$createElement("box"),
283
+ _el$2 = _$createElement("text"),
284
+ _el$3 = _$createElement("text");
285
+ _$insertNode(_el$, _el$2);
286
+ _$insertNode(_el$, _el$3);
287
+ _$setProp(_el$, "flexDirection", 'column');
288
+ _$setProp(_el$, "padding", 1);
289
+ _$setProp(_el$, "width", '100%');
290
+ _$insert(_el$2, title);
291
+ _$insert(_el$3, text);
292
+ return _el$;
293
+ })());
294
+ }
295
+
296
+ /**
297
+ * Collects an action's inputs, confirms it when it carries a confirmation,
298
+ * applies it and redraws the section from the refreshed menu. A long
299
+ * message (a sign-in URL, a reset result) is shown in full; a short one is a
300
+ * toast over the redrawn section.
301
+ */
302
+ async function runAction(context, command, menu, section, item, action) {
303
+ const {
304
+ api,
305
+ apply
306
+ } = context;
307
+ const back = () => item ? showItem(context, command, menu, section, item.id) : showSection(context, command, menu, section.id);
308
+ const values = {};
309
+ for (const knob of action.knobs) {
310
+ const value = await askKnob(api, action.label, knob);
311
+ if (value === undefined) {
312
+ back();
313
+ return;
314
+ }
315
+ values[knob.id] = value;
316
+ }
317
+ let confirmed = false;
318
+ if (action.confirm) {
319
+ confirmed = await askConfirmation(api, action.label, action.confirm.message);
320
+ if (!confirmed) {
321
+ back();
322
+ return;
323
+ }
324
+ }
325
+ const request = {
326
+ command,
327
+ sectionId: section.id,
328
+ ...(item ? {
329
+ itemId: item.id
330
+ } : {}),
331
+ actionId: action.id,
332
+ values,
333
+ ...(confirmed ? {
334
+ confirmed: true
335
+ } : {})
336
+ };
337
+ let result;
338
+ try {
339
+ result = await apply(request);
340
+ } catch (error) {
341
+ log.warn('menu apply failed', {
342
+ error: error instanceof Error ? error.message : String(error)
343
+ });
344
+ api.ui.toast({
345
+ message: 'The action could not reach OpenAI auth.'
346
+ });
347
+ back();
348
+ return;
349
+ }
350
+ // The shared RPC client answers a failed call with a body of its own that
351
+ // carries no menu; redraw from the menu already shown then.
352
+ const next = result.menu ?? menu;
353
+ if (result.needsConfirmation) {
354
+ const yes = await askConfirmation(api, action.label, result.text);
355
+ if (yes) {
356
+ const again = await apply({
357
+ ...request,
358
+ confirmed: true
359
+ });
360
+ finish(context, command, again.menu ?? next, section.id, again);
361
+ return;
362
+ }
363
+ }
364
+ finish(context, command, next, section.id, result);
365
+ }
366
+ function finish(context, command, menu, sectionId, result) {
367
+ const {
368
+ api
369
+ } = context;
370
+ if (result.text.includes('\n') || result.text.length > 120) {
371
+ showResult(api, result.ok ? 'Done' : 'Not done', result.text);
372
+ return;
373
+ }
374
+ api.ui.toast({
375
+ message: result.text
376
+ });
377
+ showSection(context, command, menu, sectionId);
378
+ }
@@ -0,0 +1,135 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ import {
5
+ createTuiPreferenceWriter,
6
+ readTuiPreferencesFile as readCommonTuiPreferencesFile,
7
+ watchTuiPreferences as watchCommonTuiPreferences
8
+ } from "./shared/9968e3cade6969a1-index.js";
9
+ export const TUI_PREFS_FILE_ENV = "OPENCODE_TUI_PREFERENCES_FILE";
10
+ const FILE_NAME = "tui-preferences.jsonc";
11
+ export function getTuiPreferencesFile() {
12
+ const override = process.env[TUI_PREFS_FILE_ENV];
13
+ if (override)
14
+ return override;
15
+ const configDir = process.env.OPENCODE_CONFIG_DIR || join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "opencode");
16
+ return join(configDir, FILE_NAME);
17
+ }
18
+ function isRecord(value) {
19
+ return typeof value === "object" && value !== null && !Array.isArray(value);
20
+ }
21
+ export function readTuiPreferencesFile() {
22
+ return readCommonTuiPreferencesFile(getTuiPreferencesFile());
23
+ }
24
+ export const PLUGIN_KEY = "openai-auth", DEFAULT_SLOT_ORDER = 160, DEFAULT_PREFS = {
25
+ forceToTop: !1,
26
+ order: DEFAULT_SLOT_ORDER,
27
+ startCollapsed: !1,
28
+ rememberCollapsed: !0,
29
+ collapsed: null,
30
+ pollMs: 1500,
31
+ refreshDebounceMs: 200,
32
+ header: { label: "OPENAI", showVersion: !0 },
33
+ sections: {
34
+ quota: !0,
35
+ fallbackAccounts: !0,
36
+ routing: !0,
37
+ health: !0,
38
+ pacing: !0
39
+ },
40
+ appearance: {
41
+ barWidth: 10,
42
+ barFilledChar: "\u2588",
43
+ barEmptyChar: "\u2591",
44
+ warnThreshold: 50,
45
+ errorThreshold: 80
46
+ }
47
+ };
48
+ function bool(value, fallback) {
49
+ return typeof value === "boolean" ? value : fallback;
50
+ }
51
+ function int(value, fallback, min, max) {
52
+ if (typeof value !== "number" || !Number.isFinite(value))
53
+ return fallback;
54
+ return Math.min(Math.max(Math.round(value), min), max);
55
+ }
56
+ function label(value, fallback, maxLength) {
57
+ if (typeof value !== "string" || value.length === 0)
58
+ return fallback;
59
+ return value.slice(0, maxLength);
60
+ }
61
+ function char(value, fallback) {
62
+ if (typeof value !== "string")
63
+ return fallback;
64
+ return [...value][0] ?? fallback;
65
+ }
66
+ export function resolveOpenaiAuthPrefs(root) {
67
+ const entry = root[PLUGIN_KEY];
68
+ if (!isRecord(entry))
69
+ return structuredClone(DEFAULT_PREFS);
70
+ const d = DEFAULT_PREFS, header = isRecord(entry.header) ? entry.header : {}, sections = isRecord(entry.sections) ? entry.sections : {}, appearance = isRecord(entry.appearance) ? entry.appearance : {}, warnThreshold = int(appearance.warnThreshold, d.appearance.warnThreshold, 0, 99), errorThreshold = Math.max(int(appearance.errorThreshold, d.appearance.errorThreshold, 0, 100), Math.min(warnThreshold + 1, 100));
71
+ return {
72
+ forceToTop: bool(entry.forceToTop, d.forceToTop),
73
+ order: int(entry.order, d.order, -1e4, 1e4),
74
+ startCollapsed: bool(entry.startCollapsed, d.startCollapsed),
75
+ rememberCollapsed: bool(entry.rememberCollapsed, d.rememberCollapsed),
76
+ collapsed: typeof entry.collapsed === "boolean" ? entry.collapsed : null,
77
+ pollMs: int(entry.pollMs, d.pollMs, 500, 30000),
78
+ refreshDebounceMs: int(entry.refreshDebounceMs, d.refreshDebounceMs, 50, 5000),
79
+ header: {
80
+ label: label(header.label, d.header.label, 20),
81
+ showVersion: bool(header.showVersion, d.header.showVersion)
82
+ },
83
+ sections: {
84
+ quota: bool(sections.quota, d.sections.quota),
85
+ fallbackAccounts: bool(sections.fallbackAccounts, d.sections.fallbackAccounts),
86
+ routing: bool(sections.routing, d.sections.routing),
87
+ health: bool(sections.health, d.sections.health),
88
+ pacing: bool(sections.pacing, d.sections.pacing)
89
+ },
90
+ appearance: {
91
+ barWidth: int(appearance.barWidth, d.appearance.barWidth, 4, 40),
92
+ barFilledChar: char(appearance.barFilledChar, d.appearance.barFilledChar),
93
+ barEmptyChar: char(appearance.barEmptyChar, d.appearance.barEmptyChar),
94
+ warnThreshold,
95
+ errorThreshold
96
+ }
97
+ };
98
+ }
99
+ const FORCE_TOP_BASE = -1e5;
100
+ export function computeEffectiveOrder(root, pluginKey, defaultOrder) {
101
+ const entry = root[pluginKey];
102
+ if (!isRecord(entry))
103
+ return defaultOrder;
104
+ if (entry.forceToTop === !0)
105
+ return FORCE_TOP_BASE + Object.keys(root).indexOf(pluginKey);
106
+ return int(entry.order, defaultOrder, -1e4, 1e4);
107
+ }
108
+ const TEMPLATE = `// Shared preferences for opencode TUI plugins.
109
+ // One top-level key per plugin (short name). See each plugin's README for
110
+ // its supported settings. This file is safe to hand-edit; plugins update
111
+ // individual keys in place and preserve comments.
112
+ {}
113
+ `, writers = new Map;
114
+ function writerFor(file, pluginKey) {
115
+ const key = JSON.stringify([file, pluginKey]);
116
+ let writer = writers.get(key);
117
+ if (!writer) {
118
+ writer = createTuiPreferenceWriter({ file, pluginKey });
119
+ writers.set(key, writer);
120
+ }
121
+ return writer;
122
+ }
123
+ async function seedPreferencesFile(file) {
124
+ await mkdir(dirname(file), { recursive: !0 });
125
+ await writeFile(file, TEMPLATE, { encoding: "utf8", flag: "wx" }).catch(() => {});
126
+ }
127
+ let writeChain = Promise.resolve();
128
+ export function queueTuiPreferenceUpdate(pluginKey, path, value) {
129
+ const file = getTuiPreferencesFile(), writer = writerFor(file, pluginKey);
130
+ writeChain = writeChain.then(() => seedPreferencesFile(file)).then(() => writer.queueTuiPreferenceUpdate(path, value)).catch(() => {});
131
+ return writeChain;
132
+ }
133
+ export function watchTuiPreferences(onChange) {
134
+ return watchCommonTuiPreferences(getTuiPreferencesFile(), onChange);
135
+ }