@iblai/web-containers 1.67.2 → 1.68.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 (234) hide show
  1. package/dist/cjs/_virtual/index2.js +2 -2
  2. package/dist/cjs/_virtual/index3.js +2 -2
  3. package/dist/cjs/components/claw-sandbox/virtual-machine-network-section.js +146 -23
  4. package/dist/cjs/components/claw-sandbox/virtual-machine-network-section.js.map +1 -1
  5. package/dist/cjs/components/field-info.js +20 -0
  6. package/dist/cjs/components/field-info.js.map +1 -0
  7. package/dist/cjs/components/modals/edit-mentor-modal/tabs/api-tab/create-api-modal.js +4 -4
  8. package/dist/cjs/components/modals/edit-mentor-modal/tabs/api-tab/labels.js +23 -19
  9. package/dist/cjs/components/modals/edit-mentor-modal/tabs/api-tab/labels.js.map +1 -1
  10. package/dist/cjs/components/modals/edit-mentor-modal/tabs/api-tab.js +15 -20
  11. package/dist/cjs/components/modals/edit-mentor-modal/tabs/api-tab.js.map +1 -1
  12. package/dist/cjs/components/modals/edit-mentor-modal/tabs/mcp-tab/connector-dialogs.js +1 -1
  13. package/dist/cjs/components/modals/edit-mentor-modal/tabs/mcp-tab/oauth-app-fields.js +2 -2
  14. package/dist/cjs/components/modals/edit-mentor-modal/tabs/mcp-tab/oauth-app-fields.js.map +1 -1
  15. package/dist/cjs/components/modals/edit-mentor-modal/tabs/skills-tab/index.js +1 -1
  16. package/dist/cjs/components/modals/user-profile-modal.js +4 -4
  17. package/dist/cjs/components/modals/user-profile-modal.js.map +1 -1
  18. package/dist/cjs/components/platform-sidebar/account-sheet.js +2 -2
  19. package/dist/cjs/components/platform-sidebar/account-sheet.js.map +1 -1
  20. package/dist/cjs/components/platform-sidebar/footer.js +15 -14
  21. package/dist/cjs/components/platform-sidebar/footer.js.map +1 -1
  22. package/dist/cjs/components/platform-sidebar/index.js +0 -2
  23. package/dist/cjs/components/platform-sidebar/index.js.map +1 -1
  24. package/dist/cjs/components/profile/account.js +43 -25
  25. package/dist/cjs/components/profile/account.js.map +1 -1
  26. package/dist/cjs/components/profile/api/api-field-label.js +16 -0
  27. package/dist/cjs/components/profile/api/api-field-label.js.map +1 -0
  28. package/dist/cjs/components/profile/{integration/api-tab → api}/api-key-modal.js +8 -8
  29. package/dist/cjs/components/profile/api/api-key-modal.js.map +1 -0
  30. package/dist/cjs/components/profile/api/api-keys-table.js +63 -0
  31. package/dist/cjs/components/profile/api/api-keys-table.js.map +1 -0
  32. package/dist/cjs/components/profile/{integration/api-tab → api}/api-token-utils.js +37 -0
  33. package/dist/cjs/components/profile/api/api-token-utils.js.map +1 -0
  34. package/dist/cjs/components/profile/{integration/api-tab → api}/constants.js +0 -1
  35. package/dist/cjs/components/profile/api/constants.js.map +1 -0
  36. package/dist/cjs/components/profile/{integration/api-tab → api}/create-api-modal.js +18 -25
  37. package/dist/cjs/components/profile/api/create-api-modal.js.map +1 -0
  38. package/dist/cjs/components/profile/api/delete-api-modal.js +33 -0
  39. package/dist/cjs/components/profile/api/delete-api-modal.js.map +1 -0
  40. package/dist/cjs/components/profile/{integration/api-tab → api}/edit-api-modal.js +33 -27
  41. package/dist/cjs/components/profile/api/edit-api-modal.js.map +1 -0
  42. package/dist/cjs/components/profile/api/expiration-date-field.js +37 -0
  43. package/dist/cjs/components/profile/api/expiration-date-field.js.map +1 -0
  44. package/dist/cjs/components/profile/api/index.js +35 -0
  45. package/dist/cjs/components/profile/api/index.js.map +1 -0
  46. package/dist/cjs/components/profile/{integration/api-tab → api}/token-policy-fields.js +6 -6
  47. package/dist/cjs/components/profile/api/token-policy-fields.js.map +1 -0
  48. package/dist/cjs/components/profile/info-banner.js +3 -0
  49. package/dist/cjs/components/profile/info-banner.js.map +1 -1
  50. package/dist/cjs/components/profile/integration/index.js +16 -37
  51. package/dist/cjs/components/profile/integration/index.js.map +1 -1
  52. package/dist/cjs/components/profile/secrets/index.js +111 -0
  53. package/dist/cjs/components/profile/secrets/index.js.map +1 -0
  54. package/dist/cjs/components/profile/secrets/secrets-list.js +239 -0
  55. package/dist/cjs/components/profile/secrets/secrets-list.js.map +1 -0
  56. package/dist/cjs/components/profile/virtual-machine-admin/index.js +11 -17
  57. package/dist/cjs/components/profile/virtual-machine-admin/index.js.map +1 -1
  58. package/dist/cjs/components/profile/virtual-machine-admin/network-policies-section.js +4 -3
  59. package/dist/cjs/components/profile/virtual-machine-admin/network-policies-section.js.map +1 -1
  60. package/dist/cjs/components/tooltip-icon-button.js +17 -0
  61. package/dist/cjs/components/tooltip-icon-button.js.map +1 -0
  62. package/dist/cjs/components/user-profile-dropdown/index.js +2 -0
  63. package/dist/cjs/components/user-profile-dropdown/index.js.map +1 -1
  64. package/dist/cjs/components/virtual-machine/azure-config.js +44 -0
  65. package/dist/cjs/components/virtual-machine/azure-config.js.map +1 -0
  66. package/dist/cjs/components/virtual-machine/azure-model-fields.js +120 -0
  67. package/dist/cjs/components/virtual-machine/azure-model-fields.js.map +1 -0
  68. package/dist/cjs/components/virtual-machine/credential-options.js +282 -21
  69. package/dist/cjs/components/virtual-machine/credential-options.js.map +1 -1
  70. package/dist/cjs/components/virtual-machine/host-port-chip-input.js +13 -7
  71. package/dist/cjs/components/virtual-machine/host-port-chip-input.js.map +1 -1
  72. package/dist/cjs/components/virtual-machine/network-policy-dialog.js +28 -4
  73. package/dist/cjs/components/virtual-machine/network-policy-dialog.js.map +1 -1
  74. package/dist/cjs/components/virtual-machine/secret-rows.js +71 -0
  75. package/dist/cjs/components/virtual-machine/secret-rows.js.map +1 -0
  76. package/dist/cjs/components/virtual-machine/vm-secret-dialog.js +845 -154
  77. package/dist/cjs/components/virtual-machine/vm-secret-dialog.js.map +1 -1
  78. package/dist/cjs/i18n/messages/en.json.js +281 -231
  79. package/dist/cjs/i18n/messages/en.json.js.map +1 -1
  80. package/dist/cjs/i18n/messages/es.json.js +452 -402
  81. package/dist/cjs/i18n/messages/es.json.js.map +1 -1
  82. package/dist/cjs/i18n/messages/fr.json.js +460 -410
  83. package/dist/cjs/i18n/messages/fr.json.js.map +1 -1
  84. package/dist/cjs/i18n/messages/zh.json.js +459 -409
  85. package/dist/cjs/i18n/messages/zh.json.js.map +1 -1
  86. package/dist/cjs/index.js +29 -25
  87. package/dist/cjs/index.js.map +1 -1
  88. package/dist/cjs/node_modules/.pnpm/css-mediaquery@0.1.2/node_modules/css-mediaquery/index.js +1 -1
  89. package/dist/cjs/node_modules/.pnpm/matchmediaquery@0.4.2/node_modules/matchmediaquery/index.js +1 -1
  90. package/dist/cjs/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.js +1 -1
  91. package/dist/cjs/web-containers/tsconfig.build.tsbuildinfo +1 -1
  92. package/dist/esm/_virtual/index2.js +2 -2
  93. package/dist/esm/_virtual/index3.js +2 -2
  94. package/dist/esm/components/claw-sandbox/virtual-machine-network-section.js +147 -24
  95. package/dist/esm/components/claw-sandbox/virtual-machine-network-section.js.map +1 -1
  96. package/dist/esm/components/field-info.js +18 -0
  97. package/dist/esm/components/field-info.js.map +1 -0
  98. package/dist/esm/components/modals/edit-mentor-modal/tabs/api-tab/create-api-modal.js +4 -4
  99. package/dist/esm/components/modals/edit-mentor-modal/tabs/api-tab/labels.js +23 -19
  100. package/dist/esm/components/modals/edit-mentor-modal/tabs/api-tab/labels.js.map +1 -1
  101. package/dist/esm/components/modals/edit-mentor-modal/tabs/api-tab.js +15 -20
  102. package/dist/esm/components/modals/edit-mentor-modal/tabs/api-tab.js.map +1 -1
  103. package/dist/esm/components/modals/edit-mentor-modal/tabs/mcp-tab/connector-dialogs.js +1 -1
  104. package/dist/esm/components/modals/edit-mentor-modal/tabs/mcp-tab/oauth-app-fields.js +2 -2
  105. package/dist/esm/components/modals/edit-mentor-modal/tabs/mcp-tab/oauth-app-fields.js.map +1 -1
  106. package/dist/esm/components/modals/edit-mentor-modal/tabs/skills-tab/index.js +1 -1
  107. package/dist/esm/components/modals/user-profile-modal.js +4 -4
  108. package/dist/esm/components/modals/user-profile-modal.js.map +1 -1
  109. package/dist/esm/components/platform-sidebar/account-sheet.js +2 -2
  110. package/dist/esm/components/platform-sidebar/account-sheet.js.map +1 -1
  111. package/dist/esm/components/platform-sidebar/footer.js +15 -14
  112. package/dist/esm/components/platform-sidebar/footer.js.map +1 -1
  113. package/dist/esm/components/platform-sidebar/index.js +0 -2
  114. package/dist/esm/components/platform-sidebar/index.js.map +1 -1
  115. package/dist/esm/components/profile/account.js +39 -21
  116. package/dist/esm/components/profile/account.js.map +1 -1
  117. package/dist/esm/components/profile/api/api-field-label.js +14 -0
  118. package/dist/esm/components/profile/api/api-field-label.js.map +1 -0
  119. package/dist/esm/components/profile/{integration/api-tab → api}/api-key-modal.js +8 -8
  120. package/dist/esm/components/profile/api/api-key-modal.js.map +1 -0
  121. package/dist/esm/components/profile/api/api-keys-table.js +61 -0
  122. package/dist/esm/components/profile/api/api-keys-table.js.map +1 -0
  123. package/dist/esm/components/profile/{integration/api-tab → api}/api-token-utils.js +34 -1
  124. package/dist/esm/components/profile/api/api-token-utils.js.map +1 -0
  125. package/dist/esm/components/profile/{integration/api-tab → api}/constants.js +0 -1
  126. package/dist/esm/components/profile/api/constants.js.map +1 -0
  127. package/dist/esm/components/profile/{integration/api-tab → api}/create-api-modal.js +19 -26
  128. package/dist/esm/components/profile/api/create-api-modal.js.map +1 -0
  129. package/dist/esm/components/profile/api/delete-api-modal.js +31 -0
  130. package/dist/esm/components/profile/api/delete-api-modal.js.map +1 -0
  131. package/dist/esm/components/profile/{integration/api-tab → api}/edit-api-modal.js +34 -28
  132. package/dist/esm/components/profile/api/edit-api-modal.js.map +1 -0
  133. package/dist/esm/components/profile/api/expiration-date-field.js +35 -0
  134. package/dist/esm/components/profile/api/expiration-date-field.js.map +1 -0
  135. package/dist/esm/components/profile/api/index.js +30 -0
  136. package/dist/esm/components/profile/api/index.js.map +1 -0
  137. package/dist/esm/components/profile/{integration/api-tab → api}/token-policy-fields.js +6 -6
  138. package/dist/esm/components/profile/api/token-policy-fields.js.map +1 -0
  139. package/dist/esm/components/profile/info-banner.js +3 -1
  140. package/dist/esm/components/profile/info-banner.js.map +1 -1
  141. package/dist/esm/components/profile/integration/index.js +17 -38
  142. package/dist/esm/components/profile/integration/index.js.map +1 -1
  143. package/dist/esm/components/profile/secrets/index.js +106 -0
  144. package/dist/esm/components/profile/secrets/index.js.map +1 -0
  145. package/dist/esm/components/profile/secrets/secrets-list.js +237 -0
  146. package/dist/esm/components/profile/secrets/secrets-list.js.map +1 -0
  147. package/dist/esm/components/profile/virtual-machine-admin/index.js +12 -18
  148. package/dist/esm/components/profile/virtual-machine-admin/index.js.map +1 -1
  149. package/dist/esm/components/profile/virtual-machine-admin/network-policies-section.js +5 -4
  150. package/dist/esm/components/profile/virtual-machine-admin/network-policies-section.js.map +1 -1
  151. package/dist/esm/components/tooltip-icon-button.js +15 -0
  152. package/dist/esm/components/tooltip-icon-button.js.map +1 -0
  153. package/dist/esm/components/user-profile-dropdown/index.js +2 -0
  154. package/dist/esm/components/user-profile-dropdown/index.js.map +1 -1
  155. package/dist/esm/components/virtual-machine/azure-config.js +37 -0
  156. package/dist/esm/components/virtual-machine/azure-config.js.map +1 -0
  157. package/dist/esm/components/virtual-machine/azure-model-fields.js +118 -0
  158. package/dist/esm/components/virtual-machine/azure-model-fields.js.map +1 -0
  159. package/dist/esm/components/virtual-machine/credential-options.js +268 -22
  160. package/dist/esm/components/virtual-machine/credential-options.js.map +1 -1
  161. package/dist/esm/components/virtual-machine/host-port-chip-input.js +14 -8
  162. package/dist/esm/components/virtual-machine/host-port-chip-input.js.map +1 -1
  163. package/dist/esm/components/virtual-machine/network-policy-dialog.js +30 -6
  164. package/dist/esm/components/virtual-machine/network-policy-dialog.js.map +1 -1
  165. package/dist/esm/components/virtual-machine/secret-rows.js +66 -0
  166. package/dist/esm/components/virtual-machine/secret-rows.js.map +1 -0
  167. package/dist/esm/components/virtual-machine/vm-secret-dialog.js +848 -158
  168. package/dist/esm/components/virtual-machine/vm-secret-dialog.js.map +1 -1
  169. package/dist/esm/i18n/messages/en.json.js +278 -227
  170. package/dist/esm/i18n/messages/en.json.js.map +1 -1
  171. package/dist/esm/i18n/messages/es.json.js +449 -398
  172. package/dist/esm/i18n/messages/es.json.js.map +1 -1
  173. package/dist/esm/i18n/messages/fr.json.js +457 -406
  174. package/dist/esm/i18n/messages/fr.json.js.map +1 -1
  175. package/dist/esm/i18n/messages/zh.json.js +456 -405
  176. package/dist/esm/i18n/messages/zh.json.js.map +1 -1
  177. package/dist/esm/index.js +2 -0
  178. package/dist/esm/index.js.map +1 -1
  179. package/dist/esm/node_modules/.pnpm/css-mediaquery@0.1.2/node_modules/css-mediaquery/index.js +1 -1
  180. package/dist/esm/node_modules/.pnpm/matchmediaquery@0.4.2/node_modules/matchmediaquery/index.js +1 -1
  181. package/dist/esm/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.js +1 -1
  182. package/dist/esm/web-containers/tsconfig.build.tsbuildinfo +1 -1
  183. package/dist/index.d.ts +62 -29
  184. package/dist/next/index.d.ts +25 -11
  185. package/dist/package.json +1 -1
  186. package/package.json +3 -3
  187. package/dist/cjs/components/modals/edit-mentor-modal/tabs/mcp-tab/field-info.js +0 -16
  188. package/dist/cjs/components/modals/edit-mentor-modal/tabs/mcp-tab/field-info.js.map +0 -1
  189. package/dist/cjs/components/profile/integration/api-tab/api-key-modal.js.map +0 -1
  190. package/dist/cjs/components/profile/integration/api-tab/api-token-utils.js.map +0 -1
  191. package/dist/cjs/components/profile/integration/api-tab/constants.js.map +0 -1
  192. package/dist/cjs/components/profile/integration/api-tab/create-api-modal.js.map +0 -1
  193. package/dist/cjs/components/profile/integration/api-tab/delete-api-modal.js +0 -33
  194. package/dist/cjs/components/profile/integration/api-tab/delete-api-modal.js.map +0 -1
  195. package/dist/cjs/components/profile/integration/api-tab/edit-api-modal.js.map +0 -1
  196. package/dist/cjs/components/profile/integration/api-tab/expiration-date-field.js +0 -31
  197. package/dist/cjs/components/profile/integration/api-tab/expiration-date-field.js.map +0 -1
  198. package/dist/cjs/components/profile/integration/api-tab/integration-autogenerated-table.js +0 -44
  199. package/dist/cjs/components/profile/integration/api-tab/integration-autogenerated-table.js.map +0 -1
  200. package/dist/cjs/components/profile/integration/api-tab/token-policy-fields.js.map +0 -1
  201. package/dist/cjs/components/profile/integration/data-sources-tab/create-data-source-modal.js +0 -145
  202. package/dist/cjs/components/profile/integration/data-sources-tab/create-data-source-modal.js.map +0 -1
  203. package/dist/cjs/components/profile/integration/data-sources-tab/integration-data-sources-tab.js +0 -48
  204. package/dist/cjs/components/profile/integration/data-sources-tab/integration-data-sources-tab.js.map +0 -1
  205. package/dist/cjs/components/profile/integration/llms-tab/create-llm-modal.js +0 -289
  206. package/dist/cjs/components/profile/integration/llms-tab/create-llm-modal.js.map +0 -1
  207. package/dist/cjs/components/profile/integration/llms-tab/integration-llms-tab.js +0 -85
  208. package/dist/cjs/components/profile/integration/llms-tab/integration-llms-tab.js.map +0 -1
  209. package/dist/cjs/components/profile/virtual-machine-admin/vm-secrets-section.js +0 -111
  210. package/dist/cjs/components/profile/virtual-machine-admin/vm-secrets-section.js.map +0 -1
  211. package/dist/esm/components/modals/edit-mentor-modal/tabs/mcp-tab/field-info.js +0 -14
  212. package/dist/esm/components/modals/edit-mentor-modal/tabs/mcp-tab/field-info.js.map +0 -1
  213. package/dist/esm/components/profile/integration/api-tab/api-key-modal.js.map +0 -1
  214. package/dist/esm/components/profile/integration/api-tab/api-token-utils.js.map +0 -1
  215. package/dist/esm/components/profile/integration/api-tab/constants.js.map +0 -1
  216. package/dist/esm/components/profile/integration/api-tab/create-api-modal.js.map +0 -1
  217. package/dist/esm/components/profile/integration/api-tab/delete-api-modal.js +0 -31
  218. package/dist/esm/components/profile/integration/api-tab/delete-api-modal.js.map +0 -1
  219. package/dist/esm/components/profile/integration/api-tab/edit-api-modal.js.map +0 -1
  220. package/dist/esm/components/profile/integration/api-tab/expiration-date-field.js +0 -29
  221. package/dist/esm/components/profile/integration/api-tab/expiration-date-field.js.map +0 -1
  222. package/dist/esm/components/profile/integration/api-tab/integration-autogenerated-table.js +0 -42
  223. package/dist/esm/components/profile/integration/api-tab/integration-autogenerated-table.js.map +0 -1
  224. package/dist/esm/components/profile/integration/api-tab/token-policy-fields.js.map +0 -1
  225. package/dist/esm/components/profile/integration/data-sources-tab/create-data-source-modal.js +0 -143
  226. package/dist/esm/components/profile/integration/data-sources-tab/create-data-source-modal.js.map +0 -1
  227. package/dist/esm/components/profile/integration/data-sources-tab/integration-data-sources-tab.js +0 -46
  228. package/dist/esm/components/profile/integration/data-sources-tab/integration-data-sources-tab.js.map +0 -1
  229. package/dist/esm/components/profile/integration/llms-tab/create-llm-modal.js +0 -287
  230. package/dist/esm/components/profile/integration/llms-tab/create-llm-modal.js.map +0 -1
  231. package/dist/esm/components/profile/integration/llms-tab/integration-llms-tab.js +0 -83
  232. package/dist/esm/components/profile/integration/llms-tab/integration-llms-tab.js.map +0 -1
  233. package/dist/esm/components/profile/virtual-machine-admin/vm-secrets-section.js +0 -109
  234. package/dist/esm/components/profile/virtual-machine-admin/vm-secrets-section.js.map +0 -1
@@ -4,221 +4,912 @@ var jsxRuntime = require('react/jsx-runtime');
4
4
  var React = require('react');
5
5
  var sonner = require('sonner');
6
6
  var dataLayer = require('@iblai/data-layer');
7
+ var fieldInfo = require('../field-info.js');
7
8
  var button = require('../ui/button.js');
9
+ var command = require('../ui/command.js');
8
10
  var dialog = require('../ui/dialog.js');
9
11
  var input = require('../ui/input.js');
10
12
  var label = require('../ui/label.js');
11
- var radioGroup = require('../ui/radio-group.js');
12
- var select = require('../ui/select.js');
13
13
  var context = require('../../i18n/context.js');
14
14
  require('../../packages/i18n/dist/index.esm.js');
15
+ var utils = require('../../lib/utils.js');
16
+ var azureConfig = require('./azure-config.js');
17
+ var azureModelFields = require('./azure-model-fields.js');
18
+ var credentialOptions = require('./credential-options.js');
15
19
  var hostPortChipInput = require('./host-port-chip-input.js');
16
- var styles = require('./styles.js');
20
+ var secretRows = require('./secret-rows.js');
21
+ var keyRound = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/key-round.js');
17
22
  var loaderCircle = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/loader-circle.js');
18
23
 
19
- const FIELD_NAMES = [
20
- 'name',
21
- 'env_var',
22
- 'allow_hosts',
23
- 'value',
24
- 'source_credential_id',
25
- 'source_field',
26
- ];
24
+ // Stable defaults: the reset effect depends on these, so a fresh array per render would re-run it.
25
+ const NO_SERVICES = [];
26
+ const NO_CREDENTIALS = [];
27
+ const NO_ENV_VARS = [];
28
+ const NO_AI_PROVIDERS = [];
29
+ const NO_AI_KEYS = [];
30
+ const NO_FIELDS = [];
31
+ const AI_PICK_PREFIX = 'ai:';
32
+ const AZURE_OPENAI_SLUG = 'azure_openai';
33
+ const AZURE_FIELD_LABELS = {
34
+ key: 'secrets.azureKeyLabel',
35
+ host: 'secrets.azureHostLabel',
36
+ version: 'secrets.azureVersionLabel',
37
+ deployment: 'secrets.azureDeploymentLabel',
38
+ };
39
+ /**
40
+ * Read the first box's value. AI providers carry a prefix, so an AI slug
41
+ * can never collide with a service of the same name.
42
+ */
43
+ function parsePick(value) {
44
+ if (value.startsWith(AI_PICK_PREFIX)) {
45
+ return { kind: 'ai', slug: value.slice(AI_PICK_PREFIX.length) };
46
+ }
47
+ return { kind: 'service', slug: value };
48
+ }
27
49
  const NAME_MAX_LENGTH = 255;
28
- const ENV_VAR_MAX_LENGTH = 128;
29
- /** Values that look masked (`sk-****`) are rejected by the backend too. */
30
- const MASKED_VALUE_PATTERN = /\*{3,}/;
50
+ const ENV_VAR_ISSUE_KEYS = {
51
+ required: 'secrets.errorEnvVarRequired',
52
+ format: 'secrets.errorEnvVarFormat',
53
+ too_long: 'secrets.errorEnvVarTooLong',
54
+ reserved: 'secrets.errorEnvVarReserved',
55
+ taken: 'secrets.errorEnvVarTaken',
56
+ };
57
+ const fieldErrorKey = (field) => `field:${field}`;
58
+ /** A repeated AI add answers a unique-together 400 with a top-level `non_field_errors`, not a 409. */
59
+ const isUniqueTogetherError = (error) => { var _a; return Boolean((_a = error === null || error === void 0 ? void 0 : error.data) === null || _a === void 0 ? void 0 : _a.non_field_errors); };
60
+ const sameHosts = (a, b) => a.length === b.length && a.every((host, index) => host === b[index]);
31
61
  /**
32
- * Create / edit form for a VM secret. A secret gets its value in one of two
33
- * ways, offered as a choice: the admin pastes a key (stored, min 8
34
- * characters), or the secret points at one field of an integration
35
- * credential the org already saved and reads it at run time. No endpoint ever
36
- * returns the value, so the field is never prefilled — on edit it stays blank
37
- * to keep the current value — and `env_var` is read-only once created (delete
38
- * and recreate to rename). Backend 400s land next to the matching field or as
39
- * a form-level message.
62
+ * Add / Edit a key of another service, one form for every key. The lists the
63
+ * caller gives decide what opens, so nobody is ever asked whether a key is "a
64
+ * secret or a data source": AI providers give a type-to-search LLM box, whose
65
+ * pick shows its own form and is saved as its LLM credential; services give the
66
+ * same box as Service, whose pick shows that service's own fields and is saved as its
67
+ * integration credential; no list at all opens straight on a name, the key and
68
+ * the addresses it is sent to, saved as a VM secret. Lists that failed or have
69
+ * not answered never read as "only a custom key is possible": see `choices`.
70
+ * From an agent's Sandbox tab a known service's key is also bound to agents (one
71
+ * VM secret reading its key field), and `link` does only that binding for a key
72
+ * the organization already holds. The variable agents use is derived from the
73
+ * name and can be changed until saved; no key is ever shown back.
40
74
  */
41
- function VmSecretDialog({ open, onOpenChange, tenantKey, secret = null, credentials, onSaved, }) {
42
- var _a;
75
+ function VmSecretDialog({ open, onOpenChange, tenantKey, services = NO_SERVICES, credentials = NO_CREDENTIALS, aiProviders = NO_AI_PROVIDERS, aiKeys = NO_AI_KEYS, aiKeysSettled = true, aiKey = null, username, azureModels, takenEnvVars = NO_ENV_VARS, secret = null, credential = null, link = false, fromSandbox = false, fromServicesTab = false, customAllowed = true, choices = 'ready', onRetryChoices, onListOutOfDate, onSaved, toastOnSave = true, }) {
76
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
43
77
  const t = context.useT();
44
78
  const baseId = React.useId();
45
79
  const ids = {
80
+ service: `${baseId}-service`,
46
81
  name: `${baseId}-name`,
47
- envVar: `${baseId}-env-var`,
48
- envVarHelp: `${baseId}-env-var-help`,
49
- hosts: `${baseId}-hosts`,
50
- source: `${baseId}-source`,
51
- sourceValue: `${baseId}-source-value`,
52
- sourceCredential: `${baseId}-source-credential`,
53
82
  value: `${baseId}-value`,
54
83
  valueHelp: `${baseId}-value-help`,
55
- credential: `${baseId}-credential`,
56
- credentialLabel: `${baseId}-credential-label`,
57
- field: `${baseId}-field`,
58
- fieldLabel: `${baseId}-field-label`,
84
+ hosts: `${baseId}-hosts`,
85
+ envVar: `${baseId}-env-var`,
86
+ envVarHelp: `${baseId}-env-var-help`,
87
+ field: (field) => `${baseId}-field-${field}`,
59
88
  };
60
- const [createSecret, { isLoading: isCreating }] = dataLayer.useCreateVirtualMachineSecretMutation();
61
- const [updateSecret, { isLoading: isUpdating }] = dataLayer.useUpdateVirtualMachineSecretMutation();
62
- const isSaving = isCreating || isUpdating;
89
+ const firstInputRef = React.useRef(null);
90
+ const boxInputRef = React.useRef(null);
91
+ const changeButtonRef = React.useRef(null);
92
+ const moveFocusAfterSwap = React.useRef(false);
93
+ const [createSecret, { isLoading: isCreatingSecret }] = dataLayer.useCreateVirtualMachineSecretMutation();
94
+ const [updateSecret, { isLoading: isUpdatingSecret }] = dataLayer.useUpdateVirtualMachineSecretMutation();
95
+ const [createCredential, { isLoading: isCreatingCredential }] = dataLayer.useCreateIntegrationCredentialMutation();
96
+ const [updateCredential, { isLoading: isUpdatingCredential }] = dataLayer.useUpdateIntegrationCredentialMutation();
97
+ const [createLlmCredential, { isLoading: isCreatingLlmCredential }] = dataLayer.useCreateLLMCredentialMutation();
98
+ const [updateLlmCredential, { isLoading: isUpdatingLlmCredential }] = dataLayer.useUpdateLLMCredentialMutation();
99
+ const [fetchCredentials, { isFetching: isFetchingCredentials }] = dataLayer.useLazyGetIntegrationCredentialsQuery();
100
+ const isSaving = isCreatingSecret ||
101
+ isUpdatingSecret ||
102
+ isCreatingCredential ||
103
+ isUpdatingCredential ||
104
+ isCreatingLlmCredential ||
105
+ isUpdatingLlmCredential ||
106
+ isFetchingCredentials;
107
+ const isLink = credential !== null && link;
108
+ const isEditService = credential !== null && !link;
109
+ const isEditCustom = secret !== null && credential === null;
110
+ // A secret that reads a known service's key opens without its credential when
111
+ // that list is refused or has not answered. Typing a key here would cut it off
112
+ // from the service's key for good, so the form never offers to.
113
+ const readsServiceKey = isEditCustom && (secret === null || secret === void 0 ? void 0 : secret.source_credential_id) != null;
114
+ const isEditAi = aiKey !== null;
115
+ const isCreate = credential === null && secret === null && !isEditAi;
116
+ const hasAi = aiProviders.length > 0;
117
+ const hasServices = services.length > 0;
118
+ const customOnly = customAllowed && choices === 'ready' && !hasAi && !hasServices;
119
+ const isLlmBox = isCreate ? hasAi : isEditAi;
120
+ const boxLabel = t(isLlmBox ? 'secrets.fieldLlm' : 'secrets.fieldService');
121
+ const boxDisabled = choices === 'loading' || (!hasAi && !hasServices);
122
+ const bound = credential !== null && secret !== null;
123
+ const [serviceSlug, setServiceSlug] = React.useState('');
124
+ const [boxSearch, setBoxSearch] = React.useState('');
125
+ const [boxFocused, setBoxFocused] = React.useState(false);
126
+ const [fieldValues, setFieldValues] = React.useState({});
63
127
  const [name, setName] = React.useState('');
64
- const [envVar, setEnvVar] = React.useState('');
65
- const [hosts, setHosts] = React.useState([]);
66
- const [source, setSource] = React.useState('value');
67
128
  const [value, setValue] = React.useState('');
68
- const [credentialId, setCredentialId] = React.useState('');
69
- const [field, setField] = React.useState('');
129
+ const [hosts, setHosts] = React.useState([]);
130
+ const [envVar, setEnvVar] = React.useState('');
131
+ // Once the person types a variable, their text wins over the derived one.
132
+ const [envVarTouched, setEnvVarTouched] = React.useState(false);
133
+ // The service's key was saved but its sandbox binding failed: the main button retries only the binding.
134
+ const [credentialSaved, setCredentialSaved] = React.useState(false);
135
+ const [sourceFieldRefused, setSourceFieldRefused] = React.useState(false);
136
+ const [credentialReadFailed, setCredentialReadFailed] = React.useState(false);
137
+ const [azureSelected, setAzureSelected] = React.useState([]);
138
+ const [azureConfigs, setAzureConfigs] = React.useState({});
139
+ const [azureErrors, setAzureErrors] = React.useState({});
70
140
  const [fieldErrors, setFieldErrors] = React.useState({});
71
141
  const [formError, setFormError] = React.useState(null);
72
- // Start from the secret being edited (or blank) every time the dialog
73
- // opens. The value is deliberately never prefilled.
142
+ const pick = parsePick(serviceSlug);
143
+ const aiSlug = (_a = aiKey === null || aiKey === void 0 ? void 0 : aiKey.name) !== null && _a !== void 0 ? _a : (isCreate && pick.kind === 'ai' ? pick.slug : null);
144
+ const isAi = aiSlug !== null;
145
+ const aiProvider = aiSlug
146
+ ? ((_b = aiProviders.find((provider) => provider.slug === aiSlug)) !== null && _b !== void 0 ? _b : null)
147
+ : null;
148
+ const aiForm = (_d = (_c = aiProvider === null || aiProvider === void 0 ? void 0 : aiProvider.form) !== null && _c !== void 0 ? _c : credentialOptions.AI_PROVIDER_FORMS[aiSlug !== null && aiSlug !== void 0 ? aiSlug : '']) !== null && _d !== void 0 ? _d : 'fields';
149
+ const aiFields = (_e = aiProvider === null || aiProvider === void 0 ? void 0 : aiProvider.fields) !== null && _e !== void 0 ? _e : NO_FIELDS;
150
+ const heldAiSlugs = React.useMemo(() => new Set(aiKeys.map((key) => key.name)), [aiKeys]);
151
+ const heldAzure = (_f = aiKeys.find((key) => key.name === AZURE_OPENAI_SLUG)) !== null && _f !== void 0 ? _f : null;
152
+ const heldAzureModels = React.useMemo(() => { var _a; return ((_a = heldAzure === null || heldAzure === void 0 ? void 0 : heldAzure.models) !== null && _a !== void 0 ? _a : []).map((model) => model.name); }, [heldAzure]);
153
+ // A held Azure OpenAI needs the list before it is picked too: it greys out only with no model left to add.
154
+ const needsAzureModels = open &&
155
+ isCreate &&
156
+ aiProviders.some((provider) => provider.form === 'azure') &&
157
+ (aiForm === 'azure' || heldAzure !== null);
158
+ const { data: llmProviders, isLoading: isLoadingLlmProviders, isError: isLlmProvidersError, refetch: refetchLlmProviders, } = dataLayer.useGetLlmsQuery({
159
+ org: tenantKey,
160
+ // @ts-expect-error - userId is not in the generated query args but the endpoint scopes by it
161
+ userId: username !== null && username !== void 0 ? username : '',
162
+ }, { skip: !needsAzureModels || !username || azureModels !== undefined });
163
+ const allAzureModels = React.useMemo(() => {
164
+ var _a;
165
+ if (azureModels)
166
+ return azureModels;
167
+ if (!llmProviders)
168
+ return null;
169
+ const azure = llmProviders.find((provider) => provider.name === AZURE_OPENAI_SLUG);
170
+ // Typed as strings by the generated client; the endpoint answers { llm_name, display_name }.
171
+ return ((_a = azure === null || azure === void 0 ? void 0 : azure.chat_models) !== null && _a !== void 0 ? _a : []);
172
+ }, [azureModels, llmProviders]);
173
+ const pickableAzureModels = React.useMemo(() => azureConfig.availableAzureModels(allAzureModels !== null && allAzureModels !== void 0 ? allAzureModels : [], heldAzureModels), [allAzureModels, heldAzureModels]);
174
+ const azureFullyHeld = heldAzure !== null && allAzureModels !== null && pickableAzureModels.length === 0;
175
+ const azureListFailed = needsAzureModels && azureModels === undefined && (!username || Boolean(isLlmProvidersError));
176
+ const azureModelsNotice = azureListFailed
177
+ ? t('secrets.azureModelsFailed')
178
+ : allAzureModels !== null && pickableAzureModels.length === 0
179
+ ? t('secrets.azureModelsNone')
180
+ : undefined;
181
+ const selectedService = React.useMemo(() => {
182
+ var _a, _b;
183
+ if (isCreate)
184
+ return (_a = services.find((service) => service.slug === serviceSlug)) !== null && _a !== void 0 ? _a : null;
185
+ if (credential)
186
+ return (_b = services.find((service) => service.slug === credential.name)) !== null && _b !== void 0 ? _b : null;
187
+ return null;
188
+ }, [isCreate, services, serviceSlug, credential]);
189
+ const allServiceFields = React.useMemo(() => selectedService
190
+ ? selectedService.fields
191
+ : credential
192
+ ? secretRows.fieldsOfCredential(credential, services)
193
+ : [], [selectedService, credential, services]);
194
+ const serviceFields = React.useMemo(() => allServiceFields.filter((field) => !field.systemManaged), [allServiceFields]);
195
+ const knownSlug = (_h = (_g = selectedService === null || selectedService === void 0 ? void 0 : selectedService.slug) !== null && _g !== void 0 ? _g : credential === null || credential === void 0 ? void 0 : credential.name) !== null && _h !== void 0 ? _h : null;
196
+ const serviceDisplayName = (_m = (_l = (_k = (_j = selectedService === null || selectedService === void 0 ? void 0 : selectedService.displayName) !== null && _j !== void 0 ? _j : credential === null || credential === void 0 ? void 0 : credential.displayName) !== null && _k !== void 0 ? _k : aiProvider === null || aiProvider === void 0 ? void 0 : aiProvider.displayName) !== null && _l !== void 0 ? _l : aiKey === null || aiKey === void 0 ? void 0 : aiKey.displayName) !== null && _m !== void 0 ? _m : '';
197
+ const serviceLogo = (_r = (_q = (_p = (_o = selectedService === null || selectedService === void 0 ? void 0 : selectedService.logo) !== null && _o !== void 0 ? _o : credential === null || credential === void 0 ? void 0 : credential.logo) !== null && _p !== void 0 ? _p : aiKey === null || aiKey === void 0 ? void 0 : aiKey.logo) !== null && _q !== void 0 ? _q : aiProvider === null || aiProvider === void 0 ? void 0 : aiProvider.logo) !== null && _r !== void 0 ? _r : null;
198
+ const agentField = knownSlug ? credentialOptions.agentKeyField(knownSlug, allServiceFields) : null;
199
+ const isCustom = isEditCustom || (isCreate && customOnly);
200
+ const isKnown = isLink || isEditService || (isCreate && selectedService !== null);
201
+ const bindsOnCreate = isCreate && isKnown && fromSandbox && agentField !== null;
202
+ // A sign-in style key (Client ID / Client Secret) only ibl.ai can use.
203
+ const platformOnly = isCreate && isKnown && agentField === null;
204
+ const isFilePicker = knownSlug !== null && credentialOptions.SERVICE_PURPOSE[knownSlug] === 'filePicker';
205
+ const showServiceSelect = isCreate && !customOnly;
206
+ const showServiceFields = (isCreate && isKnown && !credentialSaved) || isEditService;
207
+ const asksHosts = isCustom || isLink || bindsOnCreate || (isEditService && bound);
208
+ const showEnvVar = asksHosts;
209
+ const envVarReadOnly = isEditCustom || (isEditService && bound);
210
+ const showSuggestions = !boxDisabled && boxFocused;
211
+ const addedSlugs = React.useMemo(() => new Set(credentials.map((c) => c.name)), [credentials]);
212
+ // The org's other variables; the edited secret's own is not a clash.
213
+ const taken = React.useMemo(() => takenEnvVars.filter((entry) => entry !== (secret === null || secret === void 0 ? void 0 : secret.env_var)), [takenEnvVars, secret === null || secret === void 0 ? void 0 : secret.env_var]);
214
+ // Start from what is being edited (or blank) every time the dialog opens.
215
+ // A key is deliberately never prefilled. A list answering while the dialog is
216
+ // open must not reset it, or it wipes what the person typed.
74
217
  React.useEffect(() => {
75
- var _a, _b, _c, _d;
218
+ var _a, _b, _c, _d, _e, _f;
76
219
  if (!open)
77
220
  return;
78
- setName((_a = secret === null || secret === void 0 ? void 0 : secret.name) !== null && _a !== void 0 ? _a : '');
79
- setEnvVar((_b = secret === null || secret === void 0 ? void 0 : secret.env_var) !== null && _b !== void 0 ? _b : '');
80
- setHosts((_c = secret === null || secret === void 0 ? void 0 : secret.allow_hosts) !== null && _c !== void 0 ? _c : []);
81
- const linked = (secret === null || secret === void 0 ? void 0 : secret.source_credential_id) != null;
82
- setSource(linked ? 'credential' : 'value');
221
+ setServiceSlug(credential ? credential.name : '');
222
+ setBoxSearch('');
223
+ setBoxFocused(false);
224
+ const prefilled = {};
225
+ if (credential && !link) {
226
+ for (const field of secretRows.fieldsOfCredential(credential, services)) {
227
+ if (!field.isSensitive)
228
+ prefilled[field.name] = (_a = credential.values[field.name]) !== null && _a !== void 0 ? _a : '';
229
+ }
230
+ }
231
+ setFieldValues(prefilled);
232
+ setName((_b = secret === null || secret === void 0 ? void 0 : secret.name) !== null && _b !== void 0 ? _b : '');
83
233
  setValue('');
84
- setCredentialId(linked ? String(secret.source_credential_id) : '');
85
- setField(linked ? ((_d = secret.source_field) !== null && _d !== void 0 ? _d : '') : '');
234
+ setHosts((_c = secret === null || secret === void 0 ? void 0 : secret.allow_hosts) !== null && _c !== void 0 ? _c : (credential && link ? credentialOptions.defaultHostsFor(credential.name) : []));
235
+ setEnvVar((_d = secret === null || secret === void 0 ? void 0 : secret.env_var) !== null && _d !== void 0 ? _d : '');
236
+ setEnvVarTouched(false);
237
+ setCredentialSaved(false);
238
+ setSourceFieldRefused(false);
239
+ setCredentialReadFailed(false);
240
+ setAzureSelected((_f = (_e = aiKey === null || aiKey === void 0 ? void 0 : aiKey.models) === null || _e === void 0 ? void 0 : _e.map((model) => model.name)) !== null && _f !== void 0 ? _f : []);
241
+ setAzureConfigs({});
242
+ setAzureErrors({});
243
+ setFieldErrors({});
244
+ setFormError(null);
245
+ // eslint-disable-next-line react-hooks/exhaustive-deps
246
+ }, [open, secret, credential, aiKey, link]);
247
+ // The schema can answer after an edit opened: fill in the visible values it
248
+ // adds without touching what was typed.
249
+ React.useEffect(() => {
250
+ if (!open || !credential || link)
251
+ return;
252
+ setFieldValues((current) => {
253
+ var _a;
254
+ const next = { ...current };
255
+ for (const field of secretRows.fieldsOfCredential(credential, services)) {
256
+ if (!field.isSensitive && !(field.name in next)) {
257
+ next[field.name] = (_a = credential.values[field.name]) !== null && _a !== void 0 ? _a : '';
258
+ }
259
+ }
260
+ return next;
261
+ });
262
+ }, [open, credential, link, services]);
263
+ // The variable agents use, worked out from the name (or the service and its
264
+ // key field) until the person types one of their own.
265
+ React.useEffect(() => {
266
+ if (envVarReadOnly || envVarTouched)
267
+ return;
268
+ if (isCustom) {
269
+ setEnvVar(name.trim() ? dataLayer.deriveSecretEnvVar(name, { taken }) : '');
270
+ }
271
+ else if (isKnown && agentField) {
272
+ setEnvVar(credentialOptions.deriveServiceEnvVar(serviceDisplayName, agentField, taken));
273
+ }
274
+ else {
275
+ setEnvVar('');
276
+ }
277
+ }, [
278
+ name,
279
+ isCustom,
280
+ isKnown,
281
+ agentField,
282
+ serviceDisplayName,
283
+ envVarReadOnly,
284
+ envVarTouched,
285
+ taken,
286
+ ]);
287
+ // The suggestions sit in the dialog's flow, so closing them on blur would move the
288
+ // button under the pointer mid-press and lose its click. They close once the press
289
+ // or key that took focus away is over.
290
+ React.useEffect(() => {
291
+ if (!boxFocused)
292
+ return;
293
+ const closeIfLeft = () => {
294
+ if (document.activeElement !== boxInputRef.current)
295
+ setBoxFocused(false);
296
+ };
297
+ document.addEventListener('click', closeIfLeft, true);
298
+ document.addEventListener('keyup', closeIfLeft, true);
299
+ return () => {
300
+ document.removeEventListener('click', closeIfLeft, true);
301
+ document.removeEventListener('keyup', closeIfLeft, true);
302
+ };
303
+ }, [boxFocused]);
304
+ // A pick swaps the box for the chosen row and Change swaps it back, removing the control that had focus.
305
+ React.useEffect(() => {
306
+ var _a;
307
+ if (!moveFocusAfterSwap.current)
308
+ return;
309
+ moveFocusAfterSwap.current = false;
310
+ const next = serviceSlug
311
+ ? ((_a = firstInputRef.current) !== null && _a !== void 0 ? _a : changeButtonRef.current)
312
+ : boxInputRef.current;
313
+ next === null || next === void 0 ? void 0 : next.focus();
314
+ }, [serviceSlug]);
315
+ const handleServiceChange = (next) => {
316
+ setServiceSlug(next);
317
+ setFieldValues({});
318
+ setAzureSelected([]);
319
+ setAzureConfigs({});
320
+ setAzureErrors({});
86
321
  setFieldErrors({});
87
322
  setFormError(null);
88
- }, [open, secret]);
89
- const isEdit = secret !== null;
90
- const selectedCredential = credentials.find((option) => String(option.id) === credentialId);
91
- const credentialFields = (_a = selectedCredential === null || selectedCredential === void 0 ? void 0 : selectedCredential.fields) !== null && _a !== void 0 ? _a : [];
323
+ setHosts(parsePick(next).kind === 'service' && fromSandbox ? credentialOptions.defaultHostsFor(next) : []);
324
+ };
325
+ const pickFromBox = (next) => {
326
+ moveFocusAfterSwap.current = true;
327
+ setBoxSearch('');
328
+ setBoxFocused(false);
329
+ handleServiceChange(next);
330
+ };
331
+ const reopenBox = () => {
332
+ moveFocusAfterSwap.current = true;
333
+ setEnvVarTouched(false);
334
+ handleServiceChange('');
335
+ };
336
+ const closeAfterSave = (saved) => {
337
+ onSaved === null || onSaved === void 0 ? void 0 : onSaved(saved);
338
+ onOpenChange(false);
339
+ };
340
+ /** Put a VM-secret refusal under its field; anything else becomes one generic line. */
341
+ const showSecretFailure = (error) => {
342
+ const parsed = dataLayer.getVirtualMachineApiError(error);
343
+ if (parsed.status === 403) {
344
+ setFormError(t('secrets.forbiddenWrite'));
345
+ return;
346
+ }
347
+ if (parsed.fieldErrors.source_field) {
348
+ setSourceFieldRefused(true);
349
+ setFormError(t('secrets.errorSourceField', { name: serviceDisplayName }));
350
+ return;
351
+ }
352
+ const nextErrors = {};
353
+ for (const [key, messages] of Object.entries(parsed.fieldErrors)) {
354
+ if (['name', 'env_var', 'allow_hosts', 'value'].includes(key)) {
355
+ nextErrors[key] = messages.join(' ');
356
+ }
357
+ }
358
+ if (dataLayer.isSecretEnvVarTakenMessage(parsed.message)) {
359
+ // The person never typed a derived variable, so the clash is about the name.
360
+ if (envVarTouched || !isCustom) {
361
+ nextErrors.env_var = t('secrets.errorEnvVarTaken', { envVar: envVar.trim() });
362
+ }
363
+ else {
364
+ nextErrors.name = t('secrets.errorNameTaken');
365
+ }
366
+ }
367
+ setFieldErrors(nextErrors);
368
+ if (Object.keys(nextErrors).length === 0)
369
+ setFormError(t('secrets.saveFailed'));
370
+ };
371
+ const typedValue = (field) => { var _a, _b; return (_b = (_a = fieldValues[field]) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : ''; };
372
+ const fieldText = (field) => field === 'key' ? t('secrets.fieldKey') : credentialOptions.humanizeCredentialField(field);
373
+ const aiNothingTyped = () => aiForm === 'azure'
374
+ ? Object.keys(azureConfig.touchedAzureConfigs(azureConfigs)).length === 0
375
+ : Object.values(fieldValues).every((text) => !text.trim());
376
+ const aiFieldRequiredError = (field) => field === 'key'
377
+ ? t('secrets.errorKeyRequired')
378
+ : t('secrets.errorServiceFieldRequired', { label: fieldText(field) });
379
+ const aiClientErrors = () => {
380
+ const errors = {};
381
+ if (aiForm === 'azure')
382
+ return errors;
383
+ for (const field of aiFields) {
384
+ if (field.required && !typedValue(field.name)) {
385
+ errors[fieldErrorKey(field.name)] = aiFieldRequiredError(field.name);
386
+ }
387
+ }
388
+ // The LLM PATCH stores what it is sent, so pasting the row's own `sk-***`
389
+ // would replace the real key and agents would stop answering.
390
+ for (const field of aiFields) {
391
+ if (field.isSensitive && secretRows.MASKED_VALUE_PATTERN.test(typedValue(field.name))) {
392
+ errors[fieldErrorKey(field.name)] = t('secrets.errorKeyMasked');
393
+ }
394
+ }
395
+ return errors;
396
+ };
397
+ const azureClientErrors = () => {
398
+ var _a, _b, _c, _d;
399
+ const errors = {};
400
+ if (aiForm !== 'azure')
401
+ return errors;
402
+ for (const model of azureSelected) {
403
+ if (secretRows.MASKED_VALUE_PATTERN.test((_b = (_a = azureConfigs[model]) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : '')) {
404
+ errors[`${model}.key`] = t('secrets.errorKeyMasked');
405
+ }
406
+ }
407
+ if (isEditAi)
408
+ return errors;
409
+ if (azureSelected.length === 0) {
410
+ errors.model = azureModelsNotice !== null && azureModelsNotice !== void 0 ? azureModelsNotice : t('secrets.errorAzureModelRequired');
411
+ }
412
+ for (const model of azureSelected) {
413
+ for (const field of azureConfig.AZURE_MODEL_FIELDS) {
414
+ if (!((_d = (_c = azureConfigs[model]) === null || _c === void 0 ? void 0 : _c[field]) === null || _d === void 0 ? void 0 : _d.trim())) {
415
+ errors[`${model}.${field}`] = t('secrets.errorAzureFieldRequired', {
416
+ label: t(AZURE_FIELD_LABELS[field]),
417
+ model,
418
+ });
419
+ }
420
+ }
421
+ }
422
+ return errors;
423
+ };
424
+ const aiRequestValue = () => {
425
+ if (aiForm === 'azure')
426
+ return azureConfig.touchedAzureConfigs(azureConfigs);
427
+ const value = {};
428
+ for (const field of aiFields) {
429
+ const typed = typedValue(field.name);
430
+ if (typed)
431
+ value[field.name] = typed;
432
+ }
433
+ return value;
434
+ };
435
+ const showAiFailure = (error) => {
436
+ const parsed = dataLayer.getVirtualMachineApiError(error);
437
+ if (parsed.status === 403) {
438
+ setFormError(t('secrets.forbiddenWrite'));
439
+ return;
440
+ }
441
+ if ((parsed.status === 409 || isUniqueTogetherError(error)) && isCreate) {
442
+ onListOutOfDate === null || onListOutOfDate === void 0 ? void 0 : onListOutOfDate();
443
+ setFieldErrors({
444
+ service: t(credentialOptions.isAiKeyEditable(aiProvider)
445
+ ? 'secrets.serviceAlreadyAdded'
446
+ : 'secrets.serviceAlreadyAddedNoEdit', { name: serviceDisplayName }),
447
+ });
448
+ return;
449
+ }
450
+ const nextErrors = {};
451
+ for (const field of aiFields) {
452
+ if (!parsed.fieldErrors[field.name])
453
+ continue;
454
+ nextErrors[fieldErrorKey(field.name)] =
455
+ field.isSensitive && typedValue(field.name)
456
+ ? t('secrets.keyPasteFull')
457
+ : t('secrets.errorServiceFieldRequired', { label: fieldText(field.name) });
458
+ }
459
+ setFieldErrors(nextErrors);
460
+ if (Object.keys(nextErrors).length === 0)
461
+ setFormError(t('secrets.saveFailed'));
462
+ };
463
+ const submitAi = async (slug) => {
464
+ if (isEditAi && aiNothingTyped()) {
465
+ onOpenChange(false);
466
+ return;
467
+ }
468
+ const clientErrors = aiClientErrors();
469
+ const clientAzureErrors = azureClientErrors();
470
+ setFieldErrors(clientErrors);
471
+ setAzureErrors(clientAzureErrors);
472
+ setFormError(null);
473
+ if (Object.keys(clientErrors).length > 0 || Object.keys(clientAzureErrors).length > 0)
474
+ return;
475
+ const request = {
476
+ org: tenantKey,
477
+ requestBody: { name: slug, value: aiRequestValue(), platform: tenantKey },
478
+ };
479
+ try {
480
+ if (isEditAi)
481
+ await updateLlmCredential(request).unwrap();
482
+ else
483
+ await createLlmCredential(request).unwrap();
484
+ }
485
+ catch (error) {
486
+ showAiFailure(error);
487
+ return;
488
+ }
489
+ if (toastOnSave) {
490
+ if (isEditAi) {
491
+ sonner.toast.success(t('secrets.updated', { name: serviceDisplayName }));
492
+ }
493
+ else if (aiForm === 'azure' && heldAzure) {
494
+ sonner.toast.success(t('secrets.azureModelsAdded', { count: azureSelected.length, name: serviceDisplayName }));
495
+ }
496
+ else {
497
+ sonner.toast.success(t('secrets.aiProviderAdded', { name: serviceDisplayName }));
498
+ }
499
+ }
500
+ closeAfterSave(null);
501
+ };
92
502
  const handleSubmit = async (event) => {
503
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
93
504
  event.preventDefault();
505
+ if (aiSlug) {
506
+ await submitAi(aiSlug);
507
+ return;
508
+ }
94
509
  const trimmedName = name.trim();
95
510
  const trimmedEnvVar = envVar.trim();
511
+ const trimmedValue = value.trim();
96
512
  const clientErrors = {};
97
- if (!trimmedName)
98
- clientErrors.name = t('virtualMachineSecrets.errorNameRequired');
99
- if (!isEdit) {
100
- if (!trimmedEnvVar) {
101
- clientErrors.env_var = t('virtualMachineSecrets.errorEnvVarRequired');
513
+ setSourceFieldRefused(false);
514
+ setCredentialReadFailed(false);
515
+ if (showServiceSelect && !serviceSlug) {
516
+ clientErrors.service = t(isLlmBox ? 'secrets.errorLlmRequired' : 'secrets.errorServiceRequired');
517
+ }
518
+ if (isCustom) {
519
+ if (!trimmedName)
520
+ clientErrors.name = t('secrets.errorNameRequired');
521
+ if (!isEditCustom && !trimmedValue) {
522
+ clientErrors.value = t('secrets.errorKeyRequired');
102
523
  }
103
- else if (!dataLayer.VIRTUAL_MACHINE_ENV_VAR_PATTERN.test(trimmedEnvVar)) {
104
- clientErrors.env_var = t('virtualMachineSecrets.errorEnvVarFormat');
524
+ else if (secretRows.MASKED_VALUE_PATTERN.test(trimmedValue)) {
525
+ clientErrors.value = t('secrets.errorKeyMasked');
105
526
  }
106
527
  }
107
- if (hosts.length === 0)
108
- clientErrors.allow_hosts = t('virtualMachineSecrets.errorHostsRequired');
109
- if (source === 'value') {
110
- if (!isEdit && !value) {
111
- clientErrors.value = t('virtualMachineSecrets.errorValueRequired');
112
- }
113
- else if (value && value.length < dataLayer.VIRTUAL_MACHINE_SECRET_VALUE_MIN_LENGTH) {
114
- clientErrors.value = t('virtualMachineSecrets.errorValueTooShort', {
115
- min: dataLayer.VIRTUAL_MACHINE_SECRET_VALUE_MIN_LENGTH,
116
- });
528
+ if (isCreate && isKnown && !credentialSaved) {
529
+ for (const field of serviceFields) {
530
+ if (field.required && !((_a = fieldValues[field.name]) === null || _a === void 0 ? void 0 : _a.trim())) {
531
+ clientErrors[fieldErrorKey(field.name)] = t('secrets.errorServiceFieldRequired', {
532
+ label: fieldText(field.name),
533
+ });
534
+ }
117
535
  }
118
- else if (value && MASKED_VALUE_PATTERN.test(value)) {
119
- clientErrors.value = t('virtualMachineSecrets.errorValueMasked');
536
+ }
537
+ if ((isCreate && isKnown && !credentialSaved) || isEditService) {
538
+ for (const field of serviceFields) {
539
+ const typedText = (_c = (_b = fieldValues[field.name]) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
540
+ const storedText = ((_d = credential === null || credential === void 0 ? void 0 : credential.values[field.name]) !== null && _d !== void 0 ? _d : '').trim();
541
+ if (field.isSensitive && typedText !== storedText && secretRows.MASKED_VALUE_PATTERN.test(typedText)) {
542
+ clientErrors[fieldErrorKey(field.name)] = t('secrets.errorKeyMasked');
543
+ }
120
544
  }
121
545
  }
122
- else {
123
- if (!credentialId) {
124
- clientErrors.source_credential_id = t('virtualMachineSecrets.errorCredentialRequired');
546
+ if (asksHosts && hosts.length === 0)
547
+ clientErrors.allow_hosts = t('secrets.errorHostsRequired');
548
+ if (showEnvVar && !envVarReadOnly && (!isCustom || trimmedName)) {
549
+ const issue = dataLayer.validateSecretEnvVar(trimmedEnvVar, { taken });
550
+ if (issue) {
551
+ clientErrors.env_var = t(ENV_VAR_ISSUE_KEYS[issue], {
552
+ envVar: trimmedEnvVar,
553
+ max: dataLayer.VIRTUAL_MACHINE_ENV_VAR_MAX_LENGTH,
554
+ });
125
555
  }
126
- if (!field)
127
- clientErrors.source_field = t('virtualMachineSecrets.errorFieldRequired');
128
556
  }
129
557
  setFieldErrors(clientErrors);
130
558
  setFormError(null);
131
- if (Object.keys(clientErrors).length > 0)
559
+ if (Object.values(clientErrors).some(Boolean))
132
560
  return;
133
- try {
134
- let saved;
135
- if (isEdit) {
136
- const body = { env_var: secret.env_var };
137
- if (trimmedName !== secret.name)
138
- body.name = trimmedName;
139
- if (hosts.length !== secret.allow_hosts.length ||
140
- hosts.some((host, index) => host !== secret.allow_hosts[index])) {
141
- body.allow_hosts = hosts;
142
- }
143
- if (source === 'value') {
144
- // A blank value keeps the stored one; a new value replaces it (and
145
- // drops any credential link on the backend).
146
- if (value)
147
- body.value = value;
148
- }
149
- else if (Number(credentialId) !== secret.source_credential_id ||
150
- field !== secret.source_field) {
151
- body.source_credential_id = Number(credentialId);
152
- body.source_field = field;
561
+ if (isEditCustom && secret) {
562
+ const body = { env_var: secret.env_var };
563
+ if (trimmedName !== secret.name)
564
+ body.name = trimmedName;
565
+ if (!sameHosts(hosts, secret.allow_hosts))
566
+ body.allow_hosts = hosts;
567
+ if (trimmedValue && !readsServiceKey)
568
+ body.value = trimmedValue;
569
+ if (Object.keys(body).length === 1) {
570
+ onOpenChange(false);
571
+ return;
572
+ }
573
+ try {
574
+ const saved = await updateSecret({ org: tenantKey, body }).unwrap();
575
+ if (toastOnSave)
576
+ sonner.toast.success(t('secrets.envVarUpdated'));
577
+ closeAfterSave(saved);
578
+ }
579
+ catch (error) {
580
+ showSecretFailure(error);
581
+ }
582
+ return;
583
+ }
584
+ if (isEditService && credential) {
585
+ const typed = {};
586
+ for (const field of serviceFields) {
587
+ const next = (_f = (_e = fieldValues[field.name]) === null || _e === void 0 ? void 0 : _e.trim()) !== null && _f !== void 0 ? _f : '';
588
+ const changed = next !== ((_g = credential.values[field.name]) !== null && _g !== void 0 ? _g : '').trim();
589
+ // A blank secret box keeps the key, and its masked copy is never a new key.
590
+ if (changed && (next !== '' || !field.isSensitive))
591
+ typed[field.name] = next;
592
+ }
593
+ const hostsChanged = bound && secret !== null && !sameHosts(hosts, secret.allow_hosts);
594
+ if (Object.keys(typed).length === 0 && !hostsChanged) {
595
+ onOpenChange(false);
596
+ return;
597
+ }
598
+ if (Object.keys(typed).length > 0) {
599
+ try {
600
+ await updateCredential({
601
+ org: tenantKey,
602
+ requestBody: {
603
+ name: credential.name,
604
+ platform: (_h = credential.platform) !== null && _h !== void 0 ? _h : tenantKey,
605
+ value: typed,
606
+ },
607
+ }).unwrap();
153
608
  }
154
- if (Object.keys(body).length === 1) {
155
- onOpenChange(false);
609
+ catch (error) {
610
+ const parsed = dataLayer.getVirtualMachineApiError(error);
611
+ const firstSecretField = serviceFields.find((field) => field.isSensitive);
612
+ if (parsed.status === 403)
613
+ setFormError(t('secrets.forbiddenWrite'));
614
+ else if (firstSecretField) {
615
+ setFieldErrors({ [fieldErrorKey(firstSecretField.name)]: t('secrets.keyPasteFull') });
616
+ }
617
+ else
618
+ setFormError(t('secrets.saveFailed'));
156
619
  return;
157
620
  }
158
- saved = await updateSecret({ org: tenantKey, body }).unwrap();
159
- sonner.toast.success(t('virtualMachineSecrets.updated'));
160
621
  }
161
- else {
162
- const body = {
163
- name: trimmedName,
164
- env_var: trimmedEnvVar,
165
- allow_hosts: hosts,
166
- ...(source === 'value'
167
- ? { value }
168
- : { source_credential_id: Number(credentialId), source_field: field }),
169
- };
170
- saved = await createSecret({ org: tenantKey, body }).unwrap();
171
- sonner.toast.success(t('virtualMachineSecrets.created'));
172
- }
173
- onSaved === null || onSaved === void 0 ? void 0 : onSaved(saved);
174
- onOpenChange(false);
622
+ try {
623
+ let saved = secret;
624
+ if (hostsChanged && secret) {
625
+ saved = await updateSecret({
626
+ org: tenantKey,
627
+ body: { env_var: secret.env_var, allow_hosts: hosts },
628
+ }).unwrap();
629
+ }
630
+ if (toastOnSave)
631
+ sonner.toast.success(t('secrets.updated', { name: serviceDisplayName }));
632
+ closeAfterSave(saved);
633
+ }
634
+ catch (error) {
635
+ showSecretFailure(error);
636
+ }
637
+ return;
175
638
  }
176
- catch (error) {
177
- const parsed = dataLayer.getVirtualMachineApiError(error);
178
- if (parsed.status === 403) {
179
- setFormError(t('virtualMachineSecrets.forbiddenWrite'));
180
- return;
639
+ if (isLink && credential && agentField) {
640
+ try {
641
+ const saved = await createSecret({
642
+ org: tenantKey,
643
+ body: {
644
+ name: credential.displayName,
645
+ env_var: trimmedEnvVar,
646
+ allow_hosts: hosts,
647
+ source_credential_id: credential.id,
648
+ source_field: agentField,
649
+ },
650
+ }).unwrap();
651
+ if (toastOnSave) {
652
+ sonner.toast.success(t('secrets.serviceLinked', { name: credential.displayName, envVar: saved.env_var }));
653
+ }
654
+ closeAfterSave(saved);
655
+ }
656
+ catch (error) {
657
+ showSecretFailure(error);
181
658
  }
182
- const nextErrors = {};
183
- let unmatched = [];
184
- for (const [key, messages] of Object.entries(parsed.fieldErrors)) {
185
- if (FIELD_NAMES.includes(key)) {
186
- nextErrors[key] = messages.join(' ');
659
+ return;
660
+ }
661
+ if (isCreate && isKnown && knownSlug) {
662
+ if (!credentialSaved) {
663
+ // A blank optional field still goes out: the backend wants every key of the schema on a new credential.
664
+ const valueToSave = {};
665
+ for (const field of serviceFields)
666
+ valueToSave[field.name] = typedValue(field.name);
667
+ try {
668
+ await createCredential({
669
+ org: tenantKey,
670
+ requestBody: { name: knownSlug, value: valueToSave, platform: tenantKey },
671
+ }).unwrap();
187
672
  }
188
- else {
189
- unmatched = unmatched.concat(messages);
673
+ catch (error) {
674
+ const parsed = dataLayer.getVirtualMachineApiError(error);
675
+ if (parsed.status === 403)
676
+ setFormError(t('secrets.forbiddenWrite'));
677
+ else if (parsed.status === 409 || addedSlugs.has(knownSlug)) {
678
+ setFieldErrors({
679
+ service: t('secrets.serviceAlreadyAdded', { name: serviceDisplayName }),
680
+ });
681
+ }
682
+ else {
683
+ const refused = serviceFields.filter((field) => parsed.fieldErrors[field.name]);
684
+ if (refused.length > 0) {
685
+ setFieldErrors(Object.fromEntries(refused.map((field) => [
686
+ fieldErrorKey(field.name),
687
+ t('secrets.errorServiceFieldRequired', { label: fieldText(field.name) }),
688
+ ])));
689
+ }
690
+ else
691
+ setFormError(t('secrets.saveFailed'));
692
+ }
693
+ return;
694
+ }
695
+ if (!bindsOnCreate) {
696
+ if (toastOnSave) {
697
+ sonner.toast.success(t(agentField === null ? 'secrets.platformOnlyAdded' : 'secrets.serviceAdded', {
698
+ name: serviceDisplayName,
699
+ }));
700
+ }
701
+ closeAfterSave(null);
702
+ return;
190
703
  }
704
+ setCredentialSaved(true);
705
+ }
706
+ // The create response carries no id, so read the saved key back from the list.
707
+ let createdId = null;
708
+ try {
709
+ const list = await fetchCredentials({ org: tenantKey }).unwrap();
710
+ createdId =
711
+ (_k = (_j = credentialOptions.toIntegrationCredentialOptions(list, tenantKey).find((option) => option.name === knownSlug)) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k : null;
191
712
  }
192
- setFieldErrors(nextErrors);
193
- const message = [parsed.message, ...unmatched].filter(Boolean).join(' ');
194
- if (message) {
195
- setFormError(message);
713
+ catch (_l) {
714
+ createdId = null;
196
715
  }
197
- else if (Object.keys(nextErrors).length === 0) {
198
- setFormError(t('virtualMachineSecrets.saveFailed'));
716
+ if (createdId === null || !agentField) {
717
+ setCredentialReadFailed(true);
718
+ return;
719
+ }
720
+ try {
721
+ const saved = await createSecret({
722
+ org: tenantKey,
723
+ body: {
724
+ name: serviceDisplayName,
725
+ env_var: trimmedEnvVar,
726
+ allow_hosts: hosts,
727
+ source_credential_id: createdId,
728
+ source_field: agentField,
729
+ },
730
+ }).unwrap();
731
+ closeAfterSave(saved);
199
732
  }
733
+ catch (error) {
734
+ showSecretFailure(error);
735
+ }
736
+ return;
737
+ }
738
+ const body = {
739
+ name: trimmedName,
740
+ env_var: trimmedEnvVar,
741
+ allow_hosts: hosts,
742
+ value: trimmedValue,
743
+ };
744
+ try {
745
+ const saved = await createSecret({ org: tenantKey, body }).unwrap();
746
+ if (toastOnSave)
747
+ sonner.toast.success(t('secrets.customAdded', { name: trimmedName }));
748
+ closeAfterSave(saved);
749
+ }
750
+ catch (error) {
751
+ showSecretFailure(error);
200
752
  }
201
753
  };
202
754
  const fieldError = (key, id) => fieldErrors[key] ? (jsxRuntime.jsx("p", { id: `${id}-error`, role: "alert", className: "text-xs text-red-600", children: fieldErrors[key] })) : null;
203
- return (jsxRuntime.jsx(dialog.Dialog, { open: open, onOpenChange: (next) => !isSaving && onOpenChange(next), children: jsxRuntime.jsxs(dialog.DialogContent, { className: "max-h-[90vh] w-full max-w-lg overflow-y-auto", "data-testid": "vm-secret-dialog", children: [jsxRuntime.jsxs(dialog.DialogHeader, { children: [jsxRuntime.jsx(dialog.DialogTitle, { className: "ibl-dialog-title", children: isEdit ? t('virtualMachineSecrets.editTitle') : t('virtualMachineSecrets.createTitle') }), jsxRuntime.jsx(dialog.DialogDescription, { children: t('virtualMachineSecrets.dialogDescription') })] }), jsxRuntime.jsxs("form", { onSubmit: handleSubmit, noValidate: true, className: "mt-1 grid gap-5", children: [formError && (jsxRuntime.jsx("div", { role: "alert", "data-testid": "vm-secret-form-error", className: "rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700", children: formError })), jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [jsxRuntime.jsx(label.Label, { htmlFor: ids.name, className: "flex items-center text-sm font-medium text-[#646464]", children: t('virtualMachineSecrets.fieldName') }), jsxRuntime.jsx(input.Input, { id: ids.name, value: name, maxLength: NAME_MAX_LENGTH, onChange: (event) => setName(event.target.value), placeholder: t('virtualMachineSecrets.namePlaceholder'), "aria-invalid": fieldErrors.name ? true : undefined, "aria-describedby": fieldErrors.name ? `${ids.name}-error` : undefined, required: true }), fieldError('name', ids.name)] }), jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [jsxRuntime.jsx(label.Label, { htmlFor: ids.envVar, className: "flex items-center text-sm font-medium text-[#646464]", children: t('virtualMachineSecrets.fieldEnvVar') }), jsxRuntime.jsx(input.Input, { id: ids.envVar, value: envVar, maxLength: ENV_VAR_MAX_LENGTH, readOnly: isEdit, disabled: isEdit, onChange: (event) => setEnvVar(event.target.value), placeholder: t('virtualMachineSecrets.envVarPlaceholder'), autoCapitalize: "characters", autoComplete: "off", spellCheck: false, className: "font-mono", "aria-invalid": fieldErrors.env_var ? true : undefined, "aria-describedby": [ids.envVarHelp, fieldErrors.env_var ? `${ids.envVar}-error` : '']
204
- .filter(Boolean)
205
- .join(' '), required: !isEdit }), jsxRuntime.jsx("p", { id: ids.envVarHelp, className: "text-xs text-gray-500", children: isEdit
206
- ? t('virtualMachineSecrets.envVarReadOnlyHelp')
207
- : t('virtualMachineSecrets.envVarHelp') }), fieldError('env_var', ids.envVar)] }), jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [jsxRuntime.jsx(label.Label, { htmlFor: ids.hosts, className: "flex items-center text-sm font-medium text-[#646464]", children: t('virtualMachineSecrets.fieldHosts') }), jsxRuntime.jsx(hostPortChipInput.HostPortChipInput, { id: ids.hosts, value: hosts, onChange: setHosts, hint: t('virtualMachineSecrets.hostsHint'), error: fieldErrors.allow_hosts, testId: "vm-secret-hosts" })] }), jsxRuntime.jsxs("fieldset", { className: "space-y-3", children: [jsxRuntime.jsx("legend", { id: ids.source, className: "flex items-center text-sm font-medium text-[#646464]", children: t('virtualMachineSecrets.fieldSource') }), jsxRuntime.jsxs(radioGroup.RadioGroup, { value: source, onValueChange: (next) => setSource(next), "aria-labelledby": ids.source, className: "gap-3", children: [jsxRuntime.jsxs("div", { className: "flex items-start gap-3", children: [jsxRuntime.jsx(radioGroup.RadioGroupItem, { value: "value", id: ids.sourceValue, "data-testid": "vm-secret-source-value", className: styles.BLUE_RADIO_ITEM_CLASS }), jsxRuntime.jsxs(label.Label, { htmlFor: ids.sourceValue, className: "flex flex-col gap-1 font-normal", children: [jsxRuntime.jsx("span", { className: "text-[13px] font-medium text-[#646464]", children: t('virtualMachineSecrets.sourceValue') }), jsxRuntime.jsx("span", { className: "text-xs text-gray-500", children: t('virtualMachineSecrets.sourceValueDescription') })] })] }), jsxRuntime.jsxs("div", { className: "flex items-start gap-3", children: [jsxRuntime.jsx(radioGroup.RadioGroupItem, { value: "credential", id: ids.sourceCredential, "data-testid": "vm-secret-source-credential", className: styles.BLUE_RADIO_ITEM_CLASS }), jsxRuntime.jsxs(label.Label, { htmlFor: ids.sourceCredential, className: "flex flex-col gap-1 font-normal", children: [jsxRuntime.jsx("span", { className: "text-[13px] font-medium text-[#646464]", children: t('virtualMachineSecrets.sourceCredential') }), jsxRuntime.jsx("span", { className: "text-xs text-gray-500", children: t('virtualMachineSecrets.sourceCredentialDescription') })] })] })] })] }), source === 'value' ? (jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [jsxRuntime.jsx(label.Label, { htmlFor: ids.value, className: "flex items-center text-sm font-medium text-[#646464]", children: t('virtualMachineSecrets.fieldValue') }), jsxRuntime.jsx(input.Input, { id: ids.value, type: "password", value: value, onChange: (event) => setValue(event.target.value), placeholder: isEdit
208
- ? t('virtualMachineSecrets.valueKeepPlaceholder')
209
- : t('virtualMachineSecrets.valuePlaceholder'), autoComplete: "new-password", spellCheck: false, "aria-invalid": fieldErrors.value ? true : undefined, "aria-describedby": [ids.valueHelp, fieldErrors.value ? `${ids.value}-error` : '']
755
+ const labelClass = 'flex items-center gap-2 text-sm font-medium text-[#646464]';
756
+ // A label row: the label itself (the input's accessible name), the red mark
757
+ // of a required field, and the info icon.
758
+ const fieldLabel = ({ htmlFor, onClick, text, info, required = false, }) => (jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntime.jsx(label.Label, { htmlFor: htmlFor, onClick: onClick, className: "text-sm font-medium text-[#646464]", children: text }), required && (jsxRuntime.jsx("span", { className: "-ml-1 text-red-500", "aria-hidden": "true", children: "*" })), jsxRuntime.jsx(fieldInfo.FieldInfo, { label: text, text: info })] }));
759
+ const credentialFieldBox = ({ field, required, placeholder, inputRef, }) => {
760
+ var _a;
761
+ const label = fieldText(field.name);
762
+ const id = ids.field(field.name);
763
+ const errorKey = fieldErrorKey(field.name);
764
+ return (jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [fieldLabel({ htmlFor: id, text: label, info: t('secrets.serviceFieldInfo'), required }), jsxRuntime.jsx(input.Input, { ref: inputRef, id: id, type: field.isSensitive ? 'password' : 'text', value: (_a = fieldValues[field.name]) !== null && _a !== void 0 ? _a : '', onChange: (event) => setFieldValues((current) => ({
765
+ ...current,
766
+ [field.name]: event.target.value,
767
+ })), placeholder: placeholder(label), autoComplete: field.isSensitive ? 'new-password' : 'off', spellCheck: false, "aria-invalid": fieldErrors[errorKey] ? true : undefined, "aria-describedby": fieldErrors[errorKey] ? `${id}-error` : undefined, "data-testid": `vm-secret-field-${field.name}` }), fieldError(errorKey, id)] }, field.name));
768
+ };
769
+ const aiFieldBox = (field, required, first = false) => credentialFieldBox({
770
+ field,
771
+ required,
772
+ placeholder: (label) => isEditAi
773
+ ? t('secrets.keyKeepPlaceholder')
774
+ : field.name === 'key'
775
+ ? t('secrets.keyPlaceholder')
776
+ : t('secrets.serviceFieldPlaceholder', { label }),
777
+ inputRef: first ? firstInputRef : undefined,
778
+ });
779
+ const aiEditHint = isEditAi && aiForm !== 'azure' ? t('secrets.keyKeepHelp') : null;
780
+ const isAiProviderHeld = (provider) => provider.form === 'azure' ? azureFullyHeld : heldAiSlugs.has(provider.slug);
781
+ const aiEntries = aiProviders
782
+ .map((provider) => ({
783
+ value: `${AI_PICK_PREFIX}${provider.slug}`,
784
+ testId: `vm-secret-service-ai-${provider.slug}`,
785
+ displayName: provider.displayName,
786
+ logo: provider.logo,
787
+ marker: !aiKeysSettled
788
+ ? t('secrets.serviceNotLoadedMarker')
789
+ : isAiProviderHeld(provider)
790
+ ? t('secrets.serviceAddedMarker')
791
+ : null,
792
+ }))
793
+ .sort((a, b) => a.displayName.localeCompare(b.displayName));
794
+ const serviceEntries = services
795
+ .map((service) => ({
796
+ value: service.slug,
797
+ testId: `vm-secret-service-${service.slug}`,
798
+ displayName: service.displayName,
799
+ logo: service.logo,
800
+ marker: addedSlugs.has(service.slug)
801
+ ? t(fromSandbox ? 'secrets.serviceAddedMarkerSandbox' : 'secrets.serviceAddedMarker')
802
+ : null,
803
+ }))
804
+ .sort((a, b) => a.displayName.localeCompare(b.displayName));
805
+ const pickItem = (entry) => (jsxRuntime.jsxs(command.CommandItem, { value: entry.displayName, disabled: entry.marker !== null, onSelect: () => pickFromBox(entry.value), className: "cursor-pointer", "data-testid": entry.testId, children: [entry.logo ? (jsxRuntime.jsx("img", { src: entry.logo, alt: "", className: "h-4 w-4 rounded-sm object-contain" })) : (jsxRuntime.jsx(keyRound.default, { className: "h-4 w-4 text-gray-400", "aria-hidden": "true" })), entry.displayName, entry.marker && jsxRuntime.jsx("span", { className: "text-xs text-gray-400", children: entry.marker })] }, entry.value));
806
+ const pickHint = isAi
807
+ ? { text: t('secrets.aiProviderHint'), testId: 'vm-secret-ai-hint' }
808
+ : platformOnly
809
+ ? isFilePicker
810
+ ? {
811
+ text: t('secrets.filePickerPurpose', { name: serviceDisplayName }),
812
+ testId: 'vm-secret-file-picker-purpose',
813
+ }
814
+ : {
815
+ text: t('secrets.platformOnlyHint', { name: serviceDisplayName }),
816
+ testId: 'vm-secret-platform-only',
817
+ }
818
+ : isKnown && !fromSandbox
819
+ ? { text: t('secrets.serviceAgentHint'), testId: 'vm-secret-service-agent-hint' }
820
+ : null;
821
+ const addLabel = t(isCustom
822
+ ? 'secrets.addEnvVarTitle'
823
+ : isLlmBox
824
+ ? 'secrets.addLlmTitle'
825
+ : 'secrets.addServiceTitle');
826
+ // Listed as an environment variable, a bound key keeps that title even when its credential did not answer.
827
+ const editLabel = t(isEditCustom || (bound && !fromServicesTab)
828
+ ? 'secrets.editEnvVarTitle'
829
+ : isEditAi
830
+ ? 'secrets.editLlmTitle'
831
+ : 'secrets.editServiceTitle');
832
+ const title = isLink
833
+ ? t('secrets.linkTitle', { name: serviceDisplayName })
834
+ : isCreate
835
+ ? addLabel
836
+ : editLabel;
837
+ const primaryLabel = isLink ? t('secrets.save') : isCreate ? addLabel : t('secrets.saveChanges');
838
+ const keyHelpText = isEditCustom && !readsServiceKey ? t('secrets.keyKeepHelp') : null;
839
+ const keyReadFromLine = (name) => (jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [jsxRuntime.jsx("span", { className: labelClass, children: t('secrets.fieldKey') }), jsxRuntime.jsx("p", { className: "rounded-md border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700", "data-testid": "vm-secret-key-read-from", children: t('secrets.keyReadFromService', { name }) })] }));
840
+ const serviceLine = (jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-gray-900", "data-testid": "vm-secret-service", children: [serviceLogo ? (jsxRuntime.jsx("img", { src: serviceLogo, alt: "", className: "h-5 w-5 rounded-sm object-contain" })) : (jsxRuntime.jsx(keyRound.default, { className: "h-5 w-5 text-gray-400", "aria-hidden": "true" })), jsxRuntime.jsx("span", { className: "font-medium", children: serviceDisplayName })] }));
841
+ return (jsxRuntime.jsx(dialog.Dialog, { open: open, onOpenChange: (next) => !isSaving && onOpenChange(next), children: jsxRuntime.jsxs(dialog.DialogContent, { className: "max-h-[90vh] w-full max-w-lg overflow-y-auto", "data-testid": "vm-secret-dialog",
842
+ // Land in the first box, not on its info icon (whose tooltip would open).
843
+ onOpenAutoFocus: (event) => {
844
+ var _a, _b;
845
+ event.preventDefault();
846
+ // A greyed-out box refuses focus, which would leave it behind the dialog.
847
+ const box = boxInputRef.current;
848
+ ((_b = (_a = (box && !box.disabled ? box : null)) !== null && _a !== void 0 ? _a : firstInputRef.current) !== null && _b !== void 0 ? _b : event.currentTarget).focus();
849
+ }, children: [jsxRuntime.jsxs(dialog.DialogHeader, { children: [jsxRuntime.jsx(dialog.DialogTitle, { className: "ibl-dialog-title", children: title }), jsxRuntime.jsx(dialog.DialogDescription, { children: t('secrets.dialogDescription') })] }), jsxRuntime.jsxs("form", { onSubmit: handleSubmit, noValidate: true, className: "mt-1 grid gap-5", children: [showServiceSelect && (jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [fieldLabel({
850
+ // cmdk puts its own id on the input, so a `for` could not reach it.
851
+ onClick: () => { var _a; return (_a = boxInputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
852
+ text: boxLabel,
853
+ info: t(isLlmBox ? 'secrets.llmInfo' : 'secrets.serviceInfo'),
854
+ required: true,
855
+ }), serviceSlug ? (jsxRuntime.jsxs("div", { className: "border-input flex min-h-9 items-center justify-between gap-2 rounded-md border px-3 py-1", "data-testid": "vm-secret-service-picked", children: [serviceLine, !credentialSaved && (jsxRuntime.jsx(button.Button, { ref: changeButtonRef, type: "button", variant: "ghost", size: "sm", className: "h-7 cursor-pointer px-2 text-xs", disabled: isSaving, onClick: reopenBox, "data-testid": "vm-secret-service-change", children: t('secrets.changeService') }))] })) : (jsxRuntime.jsxs(command.Command, { label: boxLabel, className: utils.cn('border-input focus-within:ring-ring h-auto rounded-md border bg-transparent focus-within:ring-1', !showSuggestions && '[&_[cmdk-input-wrapper]]:border-b-0'),
856
+ // A press on a suggestion must not take focus from the box, or the list closes before its click lands.
857
+ onMouseDown: (event) => {
858
+ var _a;
859
+ if (event.target === boxInputRef.current)
860
+ return;
861
+ event.preventDefault();
862
+ (_a = boxInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
863
+ }, children: [jsxRuntime.jsx(command.CommandInput, { ref: boxInputRef, value: boxSearch, onValueChange: setBoxSearch, onFocus: () => setBoxFocused(true), disabled: boxDisabled, placeholder: t(choices === 'loading'
864
+ ? 'secrets.loading'
865
+ : isLlmBox
866
+ ? 'secrets.llmPlaceholder'
867
+ : 'secrets.servicePlaceholder'), className: "h-9 py-1", "aria-invalid": fieldErrors.service ? true : undefined, "aria-describedby": fieldErrors.service ? `${ids.service}-error` : undefined, "data-testid": "vm-secret-service-select" }), showSuggestions && (jsxRuntime.jsxs(command.CommandList, { label: boxLabel, className: "max-h-56 p-1", children: [jsxRuntime.jsx(command.CommandEmpty, { className: "px-3 py-4 text-center text-sm text-gray-500", "data-testid": "vm-secret-service-no-match", children: t(isLlmBox ? 'secrets.noMatchLlm' : 'secrets.noMatchService') }), [...aiEntries, ...serviceEntries].map(pickItem)] }))] })), pickHint && (jsxRuntime.jsx("p", { className: "text-xs text-gray-500", "data-testid": pickHint.testId, children: pickHint.text })), fieldError('service', ids.service), choices === 'failed' && (jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", "data-testid": "vm-secret-choices-failed", children: [jsxRuntime.jsx("p", { role: "alert", className: "text-xs text-red-600", children: t('secrets.choicesFailed') }), onRetryChoices && (jsxRuntime.jsx(button.Button, { type: "button", variant: "outline", size: "sm", onClick: onRetryChoices, "data-testid": "vm-secret-choices-retry", children: t('secrets.tryAgain') }))] }))] })), !isCreate && !isEditCustom && (jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [jsxRuntime.jsx("span", { className: labelClass, children: boxLabel }), serviceLine] })), credentialSaved && !sourceFieldRefused && (jsxRuntime.jsx("p", { role: "status", className: "text-sm text-gray-700", "data-testid": "vm-secret-second-write", children: t(credentialReadFailed ? 'secrets.secondWriteRetry' : 'secrets.secondWriteFailed', {
868
+ name: serviceDisplayName,
869
+ }) })), showServiceFields &&
870
+ serviceFields.map((field, index) => credentialFieldBox({
871
+ field,
872
+ required: !isEditService && field.required,
873
+ placeholder: (label) => isEditService && field.isSensitive
874
+ ? t('secrets.keyKeepPlaceholder')
875
+ : t('secrets.serviceFieldPlaceholder', { label }),
876
+ inputRef: index === 0 ? firstInputRef : undefined,
877
+ })), isAi &&
878
+ aiForm === 'fields' &&
879
+ aiFields.map((field, index) => aiFieldBox(field, field.required && !isEditAi, index === 0)), isAi && aiForm === 'azure' && (jsxRuntime.jsx(azureModelFields.AzureModelFields, { models: pickableAzureModels, selected: azureSelected, configs: azureConfigs, onSelectedChange: setAzureSelected, onConfigsChange: setAzureConfigs, mode: isEditAi ? 'edit' : 'add', errors: azureErrors, loading: Boolean(isLoadingLlmProviders), modelsNotice: azureModelsNotice, onRetryModels: isLlmProvidersError && username ? () => void refetchLlmProviders() : undefined })), aiEditHint && (jsxRuntime.jsx("p", { className: "text-xs text-gray-500", "data-testid": "vm-secret-ai-hint", children: aiEditHint })), isCustom && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [fieldLabel({
880
+ htmlFor: ids.name,
881
+ text: t('secrets.fieldName'),
882
+ info: t('secrets.nameInfo'),
883
+ required: true,
884
+ }), jsxRuntime.jsx(input.Input, { ref: firstInputRef, id: ids.name, value: name, maxLength: NAME_MAX_LENGTH, onChange: (event) => setName(event.target.value), placeholder: t('secrets.namePlaceholder'), "aria-invalid": fieldErrors.name ? true : undefined, "aria-describedby": fieldErrors.name ? `${ids.name}-error` : undefined, required: true }), fieldError('name', ids.name)] }), secret && readsServiceKey ? (keyReadFromLine(secret.name)) : (jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [fieldLabel({
885
+ htmlFor: ids.value,
886
+ text: t('secrets.fieldKey'),
887
+ info: t('secrets.keyInfo'),
888
+ required: !isEditCustom,
889
+ }), jsxRuntime.jsx(input.Input, { id: ids.value, type: "password", value: value, onChange: (event) => setValue(event.target.value), placeholder: isEditCustom ? t('secrets.keyKeepPlaceholder') : t('secrets.keyPlaceholder'), autoComplete: "new-password", spellCheck: false, "aria-invalid": fieldErrors.value ? true : undefined, "aria-describedby": [
890
+ keyHelpText ? ids.valueHelp : '',
891
+ fieldErrors.value ? `${ids.value}-error` : '',
892
+ ]
893
+ .filter(Boolean)
894
+ .join(' '), required: !isEditCustom, "data-testid": "vm-secret-value" }), keyHelpText && (jsxRuntime.jsx("p", { id: ids.valueHelp, className: "text-xs text-gray-500", children: keyHelpText })), fieldError('value', ids.value)] }))] })), isLink && keyReadFromLine(serviceDisplayName), asksHosts && (jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [fieldLabel({
895
+ htmlFor: ids.hosts,
896
+ text: t('secrets.fieldHosts'),
897
+ info: t('secrets.hostsInfo'),
898
+ required: true,
899
+ }), jsxRuntime.jsx(hostPortChipInput.HostPortChipInput, { id: ids.hosts, value: hosts, onChange: setHosts, defaultPort: dataLayer.VIRTUAL_MACHINE_DEFAULT_HOST_PORT, placeholder: t('secrets.hostsPlaceholder'), hint: isKnown ? t('secrets.serviceHostsHint') : t('secrets.hostsHint'), listLabel: t('secrets.fieldHosts'), error: fieldErrors.allow_hosts, testId: "vm-secret-hosts" })] })), showEnvVar && (jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [fieldLabel({
900
+ htmlFor: ids.envVar,
901
+ text: t('secrets.fieldEnvVar'),
902
+ info: t('secrets.envVarInfo'),
903
+ required: !envVarReadOnly,
904
+ }), jsxRuntime.jsx(input.Input, { id: ids.envVar, value: envVar, maxLength: dataLayer.VIRTUAL_MACHINE_ENV_VAR_MAX_LENGTH, readOnly: envVarReadOnly, disabled: envVarReadOnly, onChange: (event) => {
905
+ setEnvVar(event.target.value);
906
+ // Emptying the box hands the variable back to the name.
907
+ setEnvVarTouched(event.target.value.length > 0);
908
+ }, placeholder: t('secrets.envVarPlaceholder'), autoCapitalize: "characters", autoComplete: "off", spellCheck: false, className: "font-mono", "aria-invalid": fieldErrors.env_var ? true : undefined, "aria-describedby": [ids.envVarHelp, fieldErrors.env_var ? `${ids.envVar}-error` : '']
210
909
  .filter(Boolean)
211
- .join(' '), required: !isEdit, "data-testid": "vm-secret-value" }), jsxRuntime.jsx("p", { id: ids.valueHelp, className: "text-xs text-gray-500", children: isEdit
212
- ? t('virtualMachineSecrets.valueKeepHelp')
213
- : t('virtualMachineSecrets.valueHelp', {
214
- min: dataLayer.VIRTUAL_MACHINE_SECRET_VALUE_MIN_LENGTH,
215
- }) }), fieldError('value', ids.value)] })) : (jsxRuntime.jsxs("div", { className: "space-y-4", children: [jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [jsxRuntime.jsx(label.Label, { id: ids.credentialLabel, htmlFor: ids.credential, className: "flex items-center text-sm font-medium text-[#646464]", children: t('virtualMachineSecrets.fieldCredential') }), credentials.length === 0 ? (jsxRuntime.jsx("p", { className: "text-xs text-gray-500", "data-testid": "vm-secret-no-credentials", children: t('virtualMachineSecrets.noCredentials') })) : (jsxRuntime.jsxs(select.Select, { value: credentialId, onValueChange: (next) => {
216
- setCredentialId(next);
217
- setField('');
218
- }, children: [jsxRuntime.jsx(select.SelectTrigger, { id: ids.credential, "aria-labelledby": ids.credentialLabel, "aria-invalid": fieldErrors.source_credential_id ? true : undefined, "data-testid": "vm-secret-credential-select", children: jsxRuntime.jsx(select.SelectValue, { placeholder: t('virtualMachineSecrets.credentialPlaceholder') }) }), jsxRuntime.jsx(select.SelectContent, { children: credentials.map((option) => (jsxRuntime.jsx(select.SelectItem, { value: String(option.id), children: option.name }, option.id))) })] })), fieldError('source_credential_id', ids.credential)] }), jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [jsxRuntime.jsx(label.Label, { id: ids.fieldLabel, htmlFor: ids.field, className: "flex items-center text-sm font-medium text-[#646464]", children: t('virtualMachineSecrets.fieldCredentialField') }), jsxRuntime.jsxs(select.Select, { value: field, onValueChange: setField, disabled: !selectedCredential || credentialFields.length === 0, children: [jsxRuntime.jsx(select.SelectTrigger, { id: ids.field, "aria-labelledby": ids.fieldLabel, "aria-invalid": fieldErrors.source_field ? true : undefined, "data-testid": "vm-secret-field-select", children: jsxRuntime.jsx(select.SelectValue, { placeholder: t('virtualMachineSecrets.credentialFieldPlaceholder') }) }), jsxRuntime.jsx(select.SelectContent, { children: credentialFields.map((key) => (jsxRuntime.jsx(select.SelectItem, { value: key, children: key }, key))) })] }), selectedCredential && credentialFields.length === 0 && (jsxRuntime.jsx("p", { className: "text-xs text-gray-500", children: t('virtualMachineSecrets.credentialNoFields') })), fieldError('source_field', ids.field)] })] })), jsxRuntime.jsxs(dialog.DialogFooter, { children: [jsxRuntime.jsx(button.Button, { type: "button", variant: "outline", onClick: () => onOpenChange(false), disabled: isSaving, children: t('virtualMachineSecrets.cancel') }), jsxRuntime.jsxs(button.Button, { type: "submit", disabled: isSaving, "data-testid": "vm-secret-save", className: "bg-gradient-to-r from-[#2563EB] to-[#93C5FD] text-white hover:opacity-90", children: [isSaving && jsxRuntime.jsx(loaderCircle.default, { className: "h-4 w-4 animate-spin", "aria-hidden": "true" }), isEdit
219
- ? t('virtualMachineSecrets.saveChanges')
220
- : t('virtualMachineSecrets.createSecret')] })] })] })] }) }));
910
+ .join(' '), "data-testid": "vm-secret-env-var" }), jsxRuntime.jsx("p", { id: ids.envVarHelp, className: "text-xs text-gray-500", children: envVarReadOnly ? t('secrets.envVarReadOnlyHelp') : t('secrets.envVarHelp') }), fieldError('env_var', ids.envVar)] })), formError && (jsxRuntime.jsx("p", { role: "alert", "data-testid": "vm-secret-form-error", className: "text-sm text-red-600", children: formError })), jsxRuntime.jsxs(dialog.DialogFooter, { children: [jsxRuntime.jsx(button.Button, { type: "button", variant: "outline", onClick: () => onOpenChange(false), disabled: isSaving, children: t('secrets.cancel') }), jsxRuntime.jsxs(button.Button, { type: "submit", disabled: isSaving, "data-testid": "vm-secret-save", className: "bg-gradient-to-r from-[#2563EB] to-[#93C5FD] text-white hover:opacity-90", children: [isSaving && jsxRuntime.jsx(loaderCircle.default, { className: "h-4 w-4 animate-spin", "aria-hidden": "true" }), primaryLabel] })] })] })] }) }));
221
911
  }
222
912
 
223
913
  exports.VmSecretDialog = VmSecretDialog;
914
+ exports.parsePick = parsePick;
224
915
  //# sourceMappingURL=vm-secret-dialog.js.map