@sanity/assist 1.2.14 → 1.2.15-lang.10

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 (334) hide show
  1. package/README.md +546 -24
  2. package/dist/index.cjs.mjs +1 -0
  3. package/dist/index.d.ts +253 -11
  4. package/dist/index.esm.js +2367 -393
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/index.js +2361 -386
  7. package/dist/index.js.map +1 -1
  8. package/package.json +15 -14
  9. package/src/_lib/form/DocumentForm.tsx +3 -2
  10. package/src/_lib/form/constants.ts +1 -0
  11. package/src/assistDocument/AssistDocumentInput.tsx +24 -4
  12. package/src/assistDocument/RequestRunInstructionProvider.tsx +37 -21
  13. package/src/assistDocument/components/instruction/InstructionInput.tsx +5 -4
  14. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +45 -0
  15. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +205 -0
  16. package/src/assistDocument/hooks/useStudioAssistDocument.ts +5 -32
  17. package/src/assistFormComponents/AssistField.tsx +11 -5
  18. package/src/assistFormComponents/AssistFormBlock.tsx +2 -3
  19. package/src/assistFormComponents/validation/listItem.tsx +2 -2
  20. package/src/assistInspector/AssistInspector.tsx +6 -0
  21. package/src/assistInspector/FieldAutocomplete.tsx +1 -0
  22. package/src/assistInspector/InstructionTaskHistoryButton.tsx +2 -3
  23. package/src/assistInspector/helpers.ts +9 -11
  24. package/src/assistLayout/AssistLayout.tsx +9 -9
  25. package/src/components/ImageContext.tsx +19 -9
  26. package/src/components/SafeValueInput.tsx +4 -1
  27. package/src/coverage/.tmp/coverage-0.json +1 -0
  28. package/src/coverage/base.css +224 -0
  29. package/src/coverage/block-navigation.js +87 -0
  30. package/src/coverage/clover.xml +8613 -0
  31. package/src/coverage/coverage-final.json +107 -0
  32. package/src/coverage/favicon.png +0 -0
  33. package/src/coverage/index.html +461 -0
  34. package/src/coverage/lcov-report/base.css +224 -0
  35. package/src/coverage/lcov-report/block-navigation.js +87 -0
  36. package/src/coverage/lcov-report/favicon.png +0 -0
  37. package/src/coverage/lcov-report/index.html +461 -0
  38. package/src/coverage/lcov-report/prettify.css +1 -0
  39. package/src/coverage/lcov-report/prettify.js +2 -0
  40. package/src/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  41. package/src/coverage/lcov-report/sorter.js +196 -0
  42. package/src/coverage/lcov-report/src/_lib/connector/ConnectFromRegion.tsx.html +157 -0
  43. package/src/coverage/lcov-report/src/_lib/connector/ConnectToRegion.tsx.html +151 -0
  44. package/src/coverage/lcov-report/src/_lib/connector/ConnectorRegion.tsx.html +154 -0
  45. package/src/coverage/lcov-report/src/_lib/connector/ConnectorsProvider.tsx.html +142 -0
  46. package/src/coverage/lcov-report/src/_lib/connector/ConnectorsStore.ts.html +451 -0
  47. package/src/coverage/lcov-report/src/_lib/connector/ConnectorsStoreContext.ts.html +97 -0
  48. package/src/coverage/lcov-report/src/_lib/connector/helpers.ts.html +100 -0
  49. package/src/coverage/lcov-report/src/_lib/connector/index.html +281 -0
  50. package/src/coverage/lcov-report/src/_lib/connector/index.ts.html +112 -0
  51. package/src/coverage/lcov-report/src/_lib/connector/mapConnectorToLine.ts.html +334 -0
  52. package/src/coverage/lcov-report/src/_lib/connector/types.ts.html +253 -0
  53. package/src/coverage/lcov-report/src/_lib/connector/useConnectorsStore.ts.html +124 -0
  54. package/src/coverage/lcov-report/src/_lib/connector/useRegionRects.ts.html +508 -0
  55. package/src/coverage/lcov-report/src/_lib/fixedListenQuery.ts.html +388 -0
  56. package/src/coverage/lcov-report/src/_lib/form/DocumentForm.tsx.html +676 -0
  57. package/src/coverage/lcov-report/src/_lib/form/helpers.ts.html +178 -0
  58. package/src/coverage/lcov-report/src/_lib/form/index.html +146 -0
  59. package/src/coverage/lcov-report/src/_lib/form/index.ts.html +88 -0
  60. package/src/coverage/lcov-report/src/_lib/index.html +161 -0
  61. package/src/coverage/lcov-report/src/_lib/randomKey.ts.html +172 -0
  62. package/src/coverage/lcov-report/src/_lib/useListeningQuery.ts.html +268 -0
  63. package/src/coverage/lcov-report/src/_lib/usePrevious.ts.html +112 -0
  64. package/src/coverage/lcov-report/src/assistConnectors/AssistConnectorsOverlay.tsx.html +481 -0
  65. package/src/coverage/lcov-report/src/assistConnectors/ConnectorPath.tsx.html +271 -0
  66. package/src/coverage/lcov-report/src/assistConnectors/draw/arrowPath.ts.html +112 -0
  67. package/src/coverage/lcov-report/src/assistConnectors/draw/connectorPath.ts.html +511 -0
  68. package/src/coverage/lcov-report/src/assistConnectors/draw/index.html +131 -0
  69. package/src/coverage/lcov-report/src/assistConnectors/index.html +146 -0
  70. package/src/coverage/lcov-report/src/assistConnectors/index.ts.html +88 -0
  71. package/src/coverage/lcov-report/src/assistDocument/AssistDocumentContext.tsx.html +178 -0
  72. package/src/coverage/lcov-report/src/assistDocument/AssistDocumentContextProvider.tsx.html +136 -0
  73. package/src/coverage/lcov-report/src/assistDocument/AssistDocumentInput.tsx.html +280 -0
  74. package/src/coverage/lcov-report/src/assistDocument/RequestRunInstructionProvider.tsx.html +283 -0
  75. package/src/coverage/lcov-report/src/assistDocument/components/AssistDocumentForm.tsx.html +775 -0
  76. package/src/coverage/lcov-report/src/assistDocument/components/FieldRefPreview.tsx.html +166 -0
  77. package/src/coverage/lcov-report/src/assistDocument/components/InstructionsArrayField.tsx.html +109 -0
  78. package/src/coverage/lcov-report/src/assistDocument/components/InstructionsArrayInput.tsx.html +163 -0
  79. package/src/coverage/lcov-report/src/assistDocument/components/SelectedFieldContext.tsx.html +115 -0
  80. package/src/coverage/lcov-report/src/assistDocument/components/generic/HiddenFieldTitle.tsx.html +100 -0
  81. package/src/coverage/lcov-report/src/assistDocument/components/generic/index.html +116 -0
  82. package/src/coverage/lcov-report/src/assistDocument/components/helpers.ts.html +148 -0
  83. package/src/coverage/lcov-report/src/assistDocument/components/index.html +191 -0
  84. package/src/coverage/lcov-report/src/assistDocument/components/instruction/BackToInstructionsLink.tsx.html +178 -0
  85. package/src/coverage/lcov-report/src/assistDocument/components/instruction/FieldRefInput.tsx.html +244 -0
  86. package/src/coverage/lcov-report/src/assistDocument/components/instruction/InstructionInput.tsx.html +349 -0
  87. package/src/coverage/lcov-report/src/assistDocument/components/instruction/InstructionOutputField.tsx.html +220 -0
  88. package/src/coverage/lcov-report/src/assistDocument/components/instruction/InstructionOutputInput.tsx.html +700 -0
  89. package/src/coverage/lcov-report/src/assistDocument/components/instruction/PromptInput.tsx.html +241 -0
  90. package/src/coverage/lcov-report/src/assistDocument/components/instruction/appearance/IconInput.tsx.html +223 -0
  91. package/src/coverage/lcov-report/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx.html +196 -0
  92. package/src/coverage/lcov-report/src/assistDocument/components/instruction/appearance/index.html +131 -0
  93. package/src/coverage/lcov-report/src/assistDocument/components/instruction/index.html +191 -0
  94. package/src/coverage/lcov-report/src/assistDocument/hooks/index.html +161 -0
  95. package/src/coverage/lcov-report/src/assistDocument/hooks/useAssistDocumentContextValue.tsx.html +289 -0
  96. package/src/coverage/lcov-report/src/assistDocument/hooks/useDocumentState.ts.html +103 -0
  97. package/src/coverage/lcov-report/src/assistDocument/hooks/useInstructionToaster.tsx.html +307 -0
  98. package/src/coverage/lcov-report/src/assistDocument/hooks/useStudioAssistDocument.ts.html +379 -0
  99. package/src/coverage/lcov-report/src/assistDocument/index.html +176 -0
  100. package/src/coverage/lcov-report/src/assistDocument/index.ts.html +88 -0
  101. package/src/coverage/lcov-report/src/assistFormComponents/AssistField.tsx.html +301 -0
  102. package/src/coverage/lcov-report/src/assistFormComponents/AssistFormBlock.tsx.html +175 -0
  103. package/src/coverage/lcov-report/src/assistFormComponents/AssistInlineFormBlock.tsx.html +124 -0
  104. package/src/coverage/lcov-report/src/assistFormComponents/AssistItem.tsx.html +145 -0
  105. package/src/coverage/lcov-report/src/assistFormComponents/index.html +161 -0
  106. package/src/coverage/lcov-report/src/assistFormComponents/validation/index.html +131 -0
  107. package/src/coverage/lcov-report/src/assistFormComponents/validation/listItem.tsx.html +274 -0
  108. package/src/coverage/lcov-report/src/assistFormComponents/validation/validationList.tsx.html +352 -0
  109. package/src/coverage/lcov-report/src/assistInspector/AssistInspector.tsx.html +1318 -0
  110. package/src/coverage/lcov-report/src/assistInspector/FieldAutocomplete.tsx.html +505 -0
  111. package/src/coverage/lcov-report/src/assistInspector/InstructionTaskHistoryButton.tsx.html +865 -0
  112. package/src/coverage/lcov-report/src/assistInspector/constants.ts.html +88 -0
  113. package/src/coverage/lcov-report/src/assistInspector/helpers.ts.html +724 -0
  114. package/src/coverage/lcov-report/src/assistInspector/index.html +191 -0
  115. package/src/coverage/lcov-report/src/assistInspector/index.ts.html +163 -0
  116. package/src/coverage/lcov-report/src/assistLayout/AiAssistanceConfigContext.tsx.html +331 -0
  117. package/src/coverage/lcov-report/src/assistLayout/AssistLayout.tsx.html +199 -0
  118. package/src/coverage/lcov-report/src/assistLayout/RunInstructionProvider.tsx.html +751 -0
  119. package/src/coverage/lcov-report/src/assistLayout/index.html +146 -0
  120. package/src/coverage/lcov-report/src/components/AssistFeatureBadge.tsx.html +112 -0
  121. package/src/coverage/lcov-report/src/components/FadeInContent.tsx.html +205 -0
  122. package/src/coverage/lcov-report/src/components/HideReferenceChangedBannerInput.tsx.html +160 -0
  123. package/src/coverage/lcov-report/src/components/ImageContext.tsx.html +229 -0
  124. package/src/coverage/lcov-report/src/components/SafeValueInput.tsx.html +313 -0
  125. package/src/coverage/lcov-report/src/components/TimeAgo.tsx.html +139 -0
  126. package/src/coverage/lcov-report/src/components/index.html +191 -0
  127. package/src/coverage/lcov-report/src/constants.ts.html +145 -0
  128. package/src/coverage/lcov-report/src/fieldActions/PrivateIcon.tsx.html +145 -0
  129. package/src/coverage/lcov-report/src/fieldActions/assistFieldActions.tsx.html +907 -0
  130. package/src/coverage/lcov-report/src/fieldActions/generateCaptionActions.tsx.html +259 -0
  131. package/src/coverage/lcov-report/src/fieldActions/generateImageActions.tsx.html +256 -0
  132. package/src/coverage/lcov-report/src/fieldActions/index.html +161 -0
  133. package/src/coverage/lcov-report/src/helpers/assistSupported.ts.html +226 -0
  134. package/src/coverage/lcov-report/src/helpers/conditionalMembers.ts.html +466 -0
  135. package/src/coverage/lcov-report/src/helpers/ids.ts.html +142 -0
  136. package/src/coverage/lcov-report/src/helpers/index.html +191 -0
  137. package/src/coverage/lcov-report/src/helpers/misc.ts.html +133 -0
  138. package/src/coverage/lcov-report/src/helpers/typeUtils.ts.html +208 -0
  139. package/src/coverage/lcov-report/src/helpers/useAssistSupported.ts.html +106 -0
  140. package/src/coverage/lcov-report/src/index.html +176 -0
  141. package/src/coverage/lcov-report/src/index.ts.html +112 -0
  142. package/src/coverage/lcov-report/src/onboarding/FieldActionsOnboarding.tsx.html +286 -0
  143. package/src/coverage/lcov-report/src/onboarding/FirstAssistedPathProvider.tsx.html +172 -0
  144. package/src/coverage/lcov-report/src/onboarding/InspectorOnboarding.tsx.html +223 -0
  145. package/src/coverage/lcov-report/src/onboarding/index.html +161 -0
  146. package/src/coverage/lcov-report/src/onboarding/onboardingStore.ts.html +184 -0
  147. package/src/coverage/lcov-report/src/plugin.tsx.html +427 -0
  148. package/src/coverage/lcov-report/src/presence/AiFieldPresence.tsx.html +163 -0
  149. package/src/coverage/lcov-report/src/presence/AssistAvatar.tsx.html +373 -0
  150. package/src/coverage/lcov-report/src/presence/AssistDocumentPresence.tsx.html +259 -0
  151. package/src/coverage/lcov-report/src/presence/index.html +161 -0
  152. package/src/coverage/lcov-report/src/presence/useAssistPresence.ts.html +268 -0
  153. package/src/coverage/lcov-report/src/schemas/assistDocumentSchema.tsx.html +1552 -0
  154. package/src/coverage/lcov-report/src/schemas/contextDocumentSchema.tsx.html +253 -0
  155. package/src/coverage/lcov-report/src/schemas/index.html +176 -0
  156. package/src/coverage/lcov-report/src/schemas/index.ts.html +277 -0
  157. package/src/coverage/lcov-report/src/schemas/serialize/SchemTypeTool.tsx.html +391 -0
  158. package/src/coverage/lcov-report/src/schemas/serialize/index.html +146 -0
  159. package/src/coverage/lcov-report/src/schemas/serialize/schemaUtils.ts.html +196 -0
  160. package/src/coverage/lcov-report/src/schemas/serialize/serializeSchema.ts.html +754 -0
  161. package/src/coverage/lcov-report/src/schemas/serializedSchemaTypeSchema.ts.html +262 -0
  162. package/src/coverage/lcov-report/src/schemas/typeDefExtensions.ts.html +397 -0
  163. package/src/coverage/lcov-report/src/translate/FieldTranslationProvider.tsx.html +1003 -0
  164. package/src/coverage/lcov-report/src/translate/getLanguageParams.ts.html +163 -0
  165. package/src/coverage/lcov-report/src/translate/index.html +191 -0
  166. package/src/coverage/lcov-report/src/translate/languageStore.ts.html +139 -0
  167. package/src/coverage/lcov-report/src/translate/paths.ts.html +577 -0
  168. package/src/coverage/lcov-report/src/translate/translateActions.tsx.html +637 -0
  169. package/src/coverage/lcov-report/src/translate/types.ts.html +565 -0
  170. package/src/coverage/lcov-report/src/types.ts.html +649 -0
  171. package/src/coverage/lcov-report/src/useApiClient.ts.html +1015 -0
  172. package/src/coverage/lcov.info +9519 -0
  173. package/src/coverage/prettify.css +1 -0
  174. package/src/coverage/prettify.js +2 -0
  175. package/src/coverage/sort-arrow-sprite.png +0 -0
  176. package/src/coverage/sorter.js +196 -0
  177. package/src/coverage/src/_lib/connector/ConnectFromRegion.tsx.html +157 -0
  178. package/src/coverage/src/_lib/connector/ConnectToRegion.tsx.html +151 -0
  179. package/src/coverage/src/_lib/connector/ConnectorRegion.tsx.html +154 -0
  180. package/src/coverage/src/_lib/connector/ConnectorsProvider.tsx.html +142 -0
  181. package/src/coverage/src/_lib/connector/ConnectorsStore.ts.html +451 -0
  182. package/src/coverage/src/_lib/connector/ConnectorsStoreContext.ts.html +97 -0
  183. package/src/coverage/src/_lib/connector/helpers.ts.html +100 -0
  184. package/src/coverage/src/_lib/connector/index.html +281 -0
  185. package/src/coverage/src/_lib/connector/index.ts.html +112 -0
  186. package/src/coverage/src/_lib/connector/mapConnectorToLine.ts.html +334 -0
  187. package/src/coverage/src/_lib/connector/types.ts.html +253 -0
  188. package/src/coverage/src/_lib/connector/useConnectorsStore.ts.html +124 -0
  189. package/src/coverage/src/_lib/connector/useRegionRects.ts.html +508 -0
  190. package/src/coverage/src/_lib/fixedListenQuery.ts.html +388 -0
  191. package/src/coverage/src/_lib/form/DocumentForm.tsx.html +676 -0
  192. package/src/coverage/src/_lib/form/helpers.ts.html +178 -0
  193. package/src/coverage/src/_lib/form/index.html +146 -0
  194. package/src/coverage/src/_lib/form/index.ts.html +88 -0
  195. package/src/coverage/src/_lib/index.html +161 -0
  196. package/src/coverage/src/_lib/randomKey.ts.html +172 -0
  197. package/src/coverage/src/_lib/useListeningQuery.ts.html +268 -0
  198. package/src/coverage/src/_lib/usePrevious.ts.html +112 -0
  199. package/src/coverage/src/assistConnectors/AssistConnectorsOverlay.tsx.html +481 -0
  200. package/src/coverage/src/assistConnectors/ConnectorPath.tsx.html +271 -0
  201. package/src/coverage/src/assistConnectors/draw/arrowPath.ts.html +112 -0
  202. package/src/coverage/src/assistConnectors/draw/connectorPath.ts.html +511 -0
  203. package/src/coverage/src/assistConnectors/draw/index.html +131 -0
  204. package/src/coverage/src/assistConnectors/index.html +146 -0
  205. package/src/coverage/src/assistConnectors/index.ts.html +88 -0
  206. package/src/coverage/src/assistDocument/AssistDocumentContext.tsx.html +178 -0
  207. package/src/coverage/src/assistDocument/AssistDocumentContextProvider.tsx.html +136 -0
  208. package/src/coverage/src/assistDocument/AssistDocumentInput.tsx.html +280 -0
  209. package/src/coverage/src/assistDocument/RequestRunInstructionProvider.tsx.html +283 -0
  210. package/src/coverage/src/assistDocument/components/AssistDocumentForm.tsx.html +775 -0
  211. package/src/coverage/src/assistDocument/components/FieldRefPreview.tsx.html +166 -0
  212. package/src/coverage/src/assistDocument/components/InstructionsArrayField.tsx.html +109 -0
  213. package/src/coverage/src/assistDocument/components/InstructionsArrayInput.tsx.html +163 -0
  214. package/src/coverage/src/assistDocument/components/SelectedFieldContext.tsx.html +115 -0
  215. package/src/coverage/src/assistDocument/components/generic/HiddenFieldTitle.tsx.html +100 -0
  216. package/src/coverage/src/assistDocument/components/generic/index.html +116 -0
  217. package/src/coverage/src/assistDocument/components/helpers.ts.html +148 -0
  218. package/src/coverage/src/assistDocument/components/index.html +191 -0
  219. package/src/coverage/src/assistDocument/components/instruction/BackToInstructionsLink.tsx.html +178 -0
  220. package/src/coverage/src/assistDocument/components/instruction/FieldRefInput.tsx.html +244 -0
  221. package/src/coverage/src/assistDocument/components/instruction/InstructionInput.tsx.html +349 -0
  222. package/src/coverage/src/assistDocument/components/instruction/InstructionOutputField.tsx.html +220 -0
  223. package/src/coverage/src/assistDocument/components/instruction/InstructionOutputInput.tsx.html +700 -0
  224. package/src/coverage/src/assistDocument/components/instruction/PromptInput.tsx.html +241 -0
  225. package/src/coverage/src/assistDocument/components/instruction/appearance/IconInput.tsx.html +223 -0
  226. package/src/coverage/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx.html +196 -0
  227. package/src/coverage/src/assistDocument/components/instruction/appearance/index.html +131 -0
  228. package/src/coverage/src/assistDocument/components/instruction/index.html +191 -0
  229. package/src/coverage/src/assistDocument/hooks/index.html +161 -0
  230. package/src/coverage/src/assistDocument/hooks/useAssistDocumentContextValue.tsx.html +289 -0
  231. package/src/coverage/src/assistDocument/hooks/useDocumentState.ts.html +103 -0
  232. package/src/coverage/src/assistDocument/hooks/useInstructionToaster.tsx.html +307 -0
  233. package/src/coverage/src/assistDocument/hooks/useStudioAssistDocument.ts.html +379 -0
  234. package/src/coverage/src/assistDocument/index.html +176 -0
  235. package/src/coverage/src/assistDocument/index.ts.html +88 -0
  236. package/src/coverage/src/assistFormComponents/AssistField.tsx.html +301 -0
  237. package/src/coverage/src/assistFormComponents/AssistFormBlock.tsx.html +175 -0
  238. package/src/coverage/src/assistFormComponents/AssistInlineFormBlock.tsx.html +124 -0
  239. package/src/coverage/src/assistFormComponents/AssistItem.tsx.html +145 -0
  240. package/src/coverage/src/assistFormComponents/index.html +161 -0
  241. package/src/coverage/src/assistFormComponents/validation/index.html +131 -0
  242. package/src/coverage/src/assistFormComponents/validation/listItem.tsx.html +274 -0
  243. package/src/coverage/src/assistFormComponents/validation/validationList.tsx.html +352 -0
  244. package/src/coverage/src/assistInspector/AssistInspector.tsx.html +1318 -0
  245. package/src/coverage/src/assistInspector/FieldAutocomplete.tsx.html +505 -0
  246. package/src/coverage/src/assistInspector/InstructionTaskHistoryButton.tsx.html +865 -0
  247. package/src/coverage/src/assistInspector/constants.ts.html +88 -0
  248. package/src/coverage/src/assistInspector/helpers.ts.html +724 -0
  249. package/src/coverage/src/assistInspector/index.html +191 -0
  250. package/src/coverage/src/assistInspector/index.ts.html +163 -0
  251. package/src/coverage/src/assistLayout/AiAssistanceConfigContext.tsx.html +331 -0
  252. package/src/coverage/src/assistLayout/AssistLayout.tsx.html +199 -0
  253. package/src/coverage/src/assistLayout/RunInstructionProvider.tsx.html +751 -0
  254. package/src/coverage/src/assistLayout/index.html +146 -0
  255. package/src/coverage/src/components/AssistFeatureBadge.tsx.html +112 -0
  256. package/src/coverage/src/components/FadeInContent.tsx.html +205 -0
  257. package/src/coverage/src/components/HideReferenceChangedBannerInput.tsx.html +160 -0
  258. package/src/coverage/src/components/ImageContext.tsx.html +229 -0
  259. package/src/coverage/src/components/SafeValueInput.tsx.html +313 -0
  260. package/src/coverage/src/components/TimeAgo.tsx.html +139 -0
  261. package/src/coverage/src/components/index.html +191 -0
  262. package/src/coverage/src/constants.ts.html +145 -0
  263. package/src/coverage/src/fieldActions/PrivateIcon.tsx.html +145 -0
  264. package/src/coverage/src/fieldActions/assistFieldActions.tsx.html +907 -0
  265. package/src/coverage/src/fieldActions/generateCaptionActions.tsx.html +259 -0
  266. package/src/coverage/src/fieldActions/generateImageActions.tsx.html +256 -0
  267. package/src/coverage/src/fieldActions/index.html +161 -0
  268. package/src/coverage/src/helpers/assistSupported.ts.html +226 -0
  269. package/src/coverage/src/helpers/conditionalMembers.ts.html +466 -0
  270. package/src/coverage/src/helpers/ids.ts.html +142 -0
  271. package/src/coverage/src/helpers/index.html +191 -0
  272. package/src/coverage/src/helpers/misc.ts.html +133 -0
  273. package/src/coverage/src/helpers/typeUtils.ts.html +208 -0
  274. package/src/coverage/src/helpers/useAssistSupported.ts.html +106 -0
  275. package/src/coverage/src/index.html +176 -0
  276. package/src/coverage/src/index.ts.html +112 -0
  277. package/src/coverage/src/onboarding/FieldActionsOnboarding.tsx.html +286 -0
  278. package/src/coverage/src/onboarding/FirstAssistedPathProvider.tsx.html +172 -0
  279. package/src/coverage/src/onboarding/InspectorOnboarding.tsx.html +223 -0
  280. package/src/coverage/src/onboarding/index.html +161 -0
  281. package/src/coverage/src/onboarding/onboardingStore.ts.html +184 -0
  282. package/src/coverage/src/plugin.tsx.html +427 -0
  283. package/src/coverage/src/presence/AiFieldPresence.tsx.html +163 -0
  284. package/src/coverage/src/presence/AssistAvatar.tsx.html +373 -0
  285. package/src/coverage/src/presence/AssistDocumentPresence.tsx.html +259 -0
  286. package/src/coverage/src/presence/index.html +161 -0
  287. package/src/coverage/src/presence/useAssistPresence.ts.html +268 -0
  288. package/src/coverage/src/schemas/assistDocumentSchema.tsx.html +1552 -0
  289. package/src/coverage/src/schemas/contextDocumentSchema.tsx.html +253 -0
  290. package/src/coverage/src/schemas/index.html +176 -0
  291. package/src/coverage/src/schemas/index.ts.html +277 -0
  292. package/src/coverage/src/schemas/serialize/SchemTypeTool.tsx.html +391 -0
  293. package/src/coverage/src/schemas/serialize/index.html +146 -0
  294. package/src/coverage/src/schemas/serialize/schemaUtils.ts.html +196 -0
  295. package/src/coverage/src/schemas/serialize/serializeSchema.ts.html +754 -0
  296. package/src/coverage/src/schemas/serializedSchemaTypeSchema.ts.html +262 -0
  297. package/src/coverage/src/schemas/typeDefExtensions.ts.html +397 -0
  298. package/src/coverage/src/translate/FieldTranslationProvider.tsx.html +1003 -0
  299. package/src/coverage/src/translate/getLanguageParams.ts.html +163 -0
  300. package/src/coverage/src/translate/index.html +191 -0
  301. package/src/coverage/src/translate/languageStore.ts.html +139 -0
  302. package/src/coverage/src/translate/paths.ts.html +577 -0
  303. package/src/coverage/src/translate/translateActions.tsx.html +637 -0
  304. package/src/coverage/src/translate/types.ts.html +565 -0
  305. package/src/coverage/src/types.ts.html +649 -0
  306. package/src/coverage/src/useApiClient.ts.html +1015 -0
  307. package/src/fieldActions/assistFieldActions.tsx +42 -13
  308. package/src/fieldActions/generateCaptionActions.tsx +2 -2
  309. package/src/fieldActions/generateImageActions.tsx +57 -0
  310. package/src/helpers/assistSupported.ts +10 -16
  311. package/src/helpers/conditionalMembers.test.ts +200 -0
  312. package/src/helpers/conditionalMembers.ts +127 -0
  313. package/src/helpers/typeUtils.ts +19 -5
  314. package/src/index.ts +3 -0
  315. package/src/node_modules/.vitest/deps/_metadata.json +8 -0
  316. package/src/node_modules/.vitest/deps/package.json +3 -0
  317. package/src/node_modules/.vitest/results.json +1 -0
  318. package/src/plugin.tsx +14 -5
  319. package/src/presence/AssistAvatar.tsx +1 -1
  320. package/src/schemas/assistDocumentSchema.tsx +40 -1
  321. package/src/schemas/serialize/serializeSchema.test.ts +239 -8
  322. package/src/schemas/serialize/serializeSchema.ts +77 -10
  323. package/src/schemas/typeDefExtensions.ts +89 -5
  324. package/src/translate/FieldTranslationProvider.tsx +306 -0
  325. package/src/translate/getLanguageParams.ts +26 -0
  326. package/src/translate/languageStore.ts +18 -0
  327. package/src/translate/paths.test.ts +133 -0
  328. package/src/translate/paths.ts +175 -0
  329. package/src/translate/translateActions.tsx +186 -0
  330. package/src/translate/types.ts +160 -0
  331. package/src/types.ts +33 -12
  332. package/src/useApiClient.ts +130 -2
  333. package/src/assistLayout/AlphaMigration.tsx +0 -310
  334. package/src/legacy-types.ts +0 -72
package/dist/index.esm.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { useClient, typed, useSchema, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, pathToString, isObjectSchemaType, stringToPath, isKeySegment, useEditState, useCurrentUser, useValidationStatus, StatusButton, FormFieldHeaderText, PatchEvent, unset, set, useFormCallbacks, FormCallbacksProvider, FormInput, setIfMissing, insert, PresenceOverlay, VirtualizerScrollInstanceProvider, useColorSchemeValue, isArraySchemaType, ObjectInputMember, defineType, defineField, defineArrayMember, getPublishedId, useSyncState, definePlugin } from 'sanity';
3
- import { Card, Stack, Box, Button, Spinner, Flex, Label, focusFirstDescendant, Text, useClickOutside, Popover, useLayer, useGlobalKeyDown, useToast, Dialog, Tooltip, TextArea, Container, Autocomplete, Breadcrumbs, Badge, useTheme, rgba, ThemeProvider, ErrorBoundary, Switch, MenuButton, Menu, MenuItem } from '@sanity/ui';
2
+ import { useClient, isArraySchemaType, typed, useSchema, isKeySegment, isDocumentSchemaType, pathToString, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, isObjectSchemaType, stringToPath as stringToPath$2, useEditState, useCurrentUser, StatusButton, FormFieldHeaderText, PatchEvent, unset, set, useFormCallbacks, FormCallbacksProvider, FormInput, setIfMissing, insert, PresenceOverlay, VirtualizerScrollInstanceProvider, useColorSchemeValue, ObjectInputMember, defineType, defineField, defineArrayMember, isArrayOfObjectsSchemaType, getPublishedId, useSyncState, definePlugin } from 'sanity';
3
+ import { Card, Stack, Box, Button, Spinner, Flex, Label, focusFirstDescendant, Text, useClickOutside, Popover, useLayer, useGlobalKeyDown, useToast, Dialog, Tooltip, TextArea, Container, Autocomplete, Breadcrumbs, Badge, useTheme, rgba, Radio, Checkbox, ThemeProvider, ErrorBoundary, Switch, MenuButton, Menu, MenuItem } from '@sanity/ui';
4
4
  import { useState, useRef, useEffect, useMemo, useCallback, createContext, useReducer, forwardRef, createElement, useContext, useId } from 'react';
5
- import { SyncIcon, DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, ErrorOutlineIcon, CheckmarkCircleIcon, CloseCircleIcon, ClockIcon, PlayIcon, SparklesIcon, ArrowLeftIcon, SearchIcon, RetryIcon, ArrowRightIcon, CloseIcon, CheckmarkIcon, icons, TokenIcon, DocumentTextIcon, ThListIcon, CodeIcon, ComposeIcon, LockIcon, ControlsIcon } from '@sanity/icons';
5
+ import { SyncIcon, DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, ErrorOutlineIcon, CheckmarkCircleIcon, CloseCircleIcon, ClockIcon, PlayIcon, SparklesIcon, ArrowLeftIcon, SearchIcon, RetryIcon, ArrowRightIcon, CloseIcon, CheckmarkIcon, icons, TokenIcon, DocumentTextIcon, ThListIcon, CodeIcon, ComposeIcon, LockIcon, TranslateIcon, ControlsIcon } from '@sanity/icons';
6
6
  import { mergeMap, share, take, filter, distinctUntilChanged, catchError, tap } from 'rxjs/operators';
7
7
  import isEqual from 'react-fast-compare';
8
8
  import { throwError, of, partition, merge, switchMap, delay, defer } from 'rxjs';
9
9
  import { exhaustMapToWithTrailing } from 'rxjs-exhaustmap-with-trailing';
10
- import { useDocumentPane, usePaneRouter, DocumentInspectorHeader, DocumentPaneProvider } from 'sanity/desk';
11
10
  import { extractWithPath } from '@sanity/mutator';
11
+ import { useDocumentPane, usePaneRouter, DocumentInspectorHeader, DocumentPaneProvider } from 'sanity/desk';
12
12
  import styled, { keyframes } from 'styled-components';
13
13
  import { minutesToMilliseconds, isAfter, addSeconds } from 'date-fns';
14
14
  import formatDistanceToNow from 'date-fns/formatDistanceToNow';
@@ -28,6 +28,8 @@ const instructionTaskTypeName = "sanity.assist.instructionTask";
28
28
  const fieldPresenceTypeName = "sanity.assist.instructionTask.presence";
29
29
  const assistSerializedTypeName = "sanity.assist.serialized.type";
30
30
  const assistSerializedFieldTypeName = "sanity.assist.serialized.field";
31
+ const outputFieldTypeName = "sanity.assist.output.field";
32
+ const outputTypeTypeName = "sanity.assist.output.type";
31
33
  const fieldPathParam = "pathKey";
32
34
  const instructionParam = "instruction";
33
35
  const documentRootKey = "<document>";
@@ -124,49 +126,59 @@ function isType(schemaType, typeName) {
124
126
  function isImage(schemaType) {
125
127
  return isType(schemaType, "image");
126
128
  }
127
- function getCaptionFieldOption(schemaType) {
128
- var _a;
129
+ function getDescriptionFieldOption(schemaType) {
130
+ var _a, _b;
131
+ if (!schemaType) {
132
+ return void 0;
133
+ }
134
+ const descriptionField = (_b = (_a = schemaType.options) == null ? void 0 : _a.aiAssist) == null ? void 0 : _b.imageDescriptionField;
135
+ if (descriptionField) {
136
+ return descriptionField;
137
+ }
138
+ return getDescriptionFieldOption(schemaType.type);
139
+ }
140
+ function getImageInstructionFieldOption(schemaType) {
141
+ var _a, _b;
129
142
  if (!schemaType) {
130
143
  return void 0;
131
144
  }
132
- const captionField = (_a = schemaType.options) == null ? void 0 : _a.captionField;
133
- if (captionField) {
134
- return captionField;
145
+ const imageInstructionField = (_b = (_a = schemaType.options) == null ? void 0 : _a.aiAssist) == null ? void 0 : _b.imageInstructionField;
146
+ if (imageInstructionField) {
147
+ return imageInstructionField;
135
148
  }
136
- return getCaptionFieldOption(schemaType.type);
149
+ return getImageInstructionFieldOption(schemaType.type);
137
150
  }
138
151
  function isSchemaAssistEnabled(type) {
139
152
  var _a, _b;
140
- return !((_b = (_a = type.options) == null ? void 0 : _a.aiWritingAssistance) == null ? void 0 : _b.exclude);
153
+ return !((_b = (_a = type.options) == null ? void 0 : _a.aiAssist) == null ? void 0 : _b.exclude);
141
154
  }
142
155
  function isAssistSupported(type) {
143
- let allowReadonlyHidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
144
156
  if (!isSchemaAssistEnabled(type)) {
145
157
  return false;
146
158
  }
147
- if (isDisabled(type, allowReadonlyHidden)) {
159
+ if (isDisabled(type)) {
148
160
  return false;
149
161
  }
150
162
  if (type.jsonType === "array") {
151
- const unsupportedArray = type.of.every(t => isDisabled(t, allowReadonlyHidden));
163
+ const unsupportedArray = type.of.every(t => isDisabled(t));
152
164
  return !unsupportedArray;
153
165
  }
154
166
  if (type.jsonType === "object") {
155
- const unsupportedObject = type.fields.every(field => isDisabled(field.type, allowReadonlyHidden));
167
+ const unsupportedObject = type.fields.every(field => isDisabled(field.type));
156
168
  return !unsupportedObject;
157
169
  }
158
170
  return true;
159
171
  }
160
- function isDisabled(type, allowReadonlyHidden) {
161
- const readonlyHidden = !!type.readOnly || !!type.hidden;
162
- return !isSchemaAssistEnabled(type) || isUnsupportedType(type) || !allowReadonlyHidden && readonlyHidden;
172
+ function isDisabled(type) {
173
+ return !isSchemaAssistEnabled(type) || isUnsupportedType(type);
163
174
  }
164
175
  function isUnsupportedType(type) {
165
- return type.jsonType === "number" || type.name === "sanity.imageCrop" || type.name === "sanity.imageHotspot" || isType(type, "reference") || isType(type, "crossDatasetReference") || isType(type, "slug") || isType(type, "url") || isType(type, "date") || isType(type, "datetime") || isType(type, "file");
176
+ var _a, _b;
177
+ return type.jsonType === "number" || type.name === "sanity.imageCrop" || type.name === "sanity.imageHotspot" || isType(type, "reference") && !((_b = (_a = type == null ? void 0 : type.options) == null ? void 0 : _a.aiAssist) == null ? void 0 : _b.embeddingsIndex) || isType(type, "crossDatasetReference") || isType(type, "slug") || isType(type, "url") || isType(type, "date") || isType(type, "datetime") || isType(type, "file");
166
178
  }
167
179
  const inlineTypes = ["document", "object", "image", "file"];
168
180
  function serializeSchema(schema, options) {
169
- const list = schema.getTypeNames().filter(t => !(hiddenTypes.includes(t) || t.startsWith("sanity."))).map(t => schema.get(t)).filter(t => !!t).filter(t => !t.hidden && !t.readOnly).map(t => getSchemaStub(t, schema, options)).filter(t => {
181
+ const list = schema.getTypeNames().filter(t => !(hiddenTypes.includes(t) || t.startsWith("sanity."))).map(t => schema.get(t)).filter(t => !!t).map(t => getSchemaStub(t, schema, options)).filter(t => {
170
182
  if ("to" in t && t.to && !t.to.length) {
171
183
  return false;
172
184
  }
@@ -204,26 +216,41 @@ function getSchemaStub(schemaType, schema, options) {
204
216
  return removeUndef(baseSchema);
205
217
  }
206
218
  function getBaseFields(schema, type, typeName, options) {
207
- var _a, _b, _c;
208
- const imagePromptField = (_a = type.options) == null ? void 0 : _a.imagePromptField;
219
+ var _a, _b, _c, _d, _e, _f;
220
+ const schemaOptions = removeUndef({
221
+ imagePromptField: (_b = (_a = type.options) == null ? void 0 : _a.aiAssist) == null ? void 0 : _b.imageInstructionField,
222
+ embeddingsIndex: (_d = (_c = type.options) == null ? void 0 : _c.aiAssist) == null ? void 0 : _d.embeddingsIndex
223
+ });
209
224
  return removeUndef({
210
- options: imagePromptField ? {
211
- imagePromptField
212
- } : void 0,
213
- values: Array.isArray((_b = type == null ? void 0 : type.options) == null ? void 0 : _b.list) ? (_c = type == null ? void 0 : type.options) == null ? void 0 : _c.list.map(v => {
225
+ options: Object.keys(schemaOptions).length ? schemaOptions : void 0,
226
+ values: Array.isArray((_e = type == null ? void 0 : type.options) == null ? void 0 : _e.list) ? (_f = type == null ? void 0 : type.options) == null ? void 0 : _f.list.map(v => {
214
227
  var _a2;
215
228
  return typeof v === "string" ? v : (_a2 = v.value) != null ? _a2 : "".concat(v.title);
216
229
  }) : void 0,
217
230
  of: "of" in type && typeName === "array" ? arrayOf(type, schema, options) : void 0,
218
231
  to: "to" in type && typeName === "reference" ? refToTypeNames(type) : void 0,
219
- fields: "fields" in type && inlineTypes.includes(typeName) ? serializeFields(schema, type, options) : void 0
232
+ fields: "fields" in type && inlineTypes.includes(typeName) ? serializeFields(schema, type, options) : void 0,
233
+ annotations: typeName === "block" && "fields" in type ? serializeAnnotations(type, schema, options) : void 0,
234
+ inlineOf: typeName === "block" && "fields" in type ? serializeInlineOf(type, schema, options) : void 0,
235
+ hidden: typeof type.hidden === "function" ? "function" : type.hidden ? true : void 0,
236
+ readOnly: typeof type.readOnly === "function" ? "function" : type.readOnly ? true : void 0
220
237
  });
221
238
  }
222
239
  function serializeFields(schema, schemaType, options) {
223
- return schemaType.fields.filter(f => {
240
+ const fields = schemaType.fieldsets ? schemaType.fieldsets.flatMap(fs => fs.single ? fs.field : fs.fields.map(f => ({
241
+ ...f,
242
+ type: {
243
+ ...f.type,
244
+ // if fieldset is (conditionally) hidden, the field must be considered the same way
245
+ // ie, if the field does not show up in conditionalMembers, it is hidden
246
+ // regardless of weather or not it is the field function or the fieldset function that hides it
247
+ hidden: typeof fs.hidden === "function" ? fs.hidden : fs.hidden ? true : f.type.hidden
248
+ }
249
+ }))) : schemaType.fields;
250
+ return fields.filter(f => {
224
251
  var _a, _b;
225
252
  return !["sanity.imageHotspot", "sanity.imageCrop"].includes((_b = (_a = f.type) == null ? void 0 : _a.name) != null ? _b : "");
226
- }).filter(f => isAssistSupported(f.type)).filter(f => !f.type.hidden && !f.type.readOnly).map(field => serializeMember(schema, field.type, field.name, options));
253
+ }).filter(f => isAssistSupported(f.type)).map(field => serializeMember(schema, field.type, field.name, options));
227
254
  }
228
255
  function serializeMember(schema, type, name, options) {
229
256
  var _a, _b;
@@ -239,6 +266,25 @@ function serializeMember(schema, type, name, options) {
239
266
  ...getBaseFields(schema, type, typeName, options)
240
267
  });
241
268
  }
269
+ function serializeInlineOf(blockSchemaType, schema, options) {
270
+ const childrenField = blockSchemaType.fields.find(f => f.name === "children");
271
+ const childrenType = childrenField == null ? void 0 : childrenField.type;
272
+ if (!childrenType || !isArraySchemaType(childrenType)) {
273
+ return void 0;
274
+ }
275
+ return arrayOf({
276
+ ...childrenType,
277
+ of: childrenType.of.filter(t => !isType(t, "span"))
278
+ }, schema, options);
279
+ }
280
+ function serializeAnnotations(blockSchemaType, schema, options) {
281
+ const markDefs = blockSchemaType.fields.find(f => f.name === "markDefs");
282
+ const marksType = markDefs == null ? void 0 : markDefs.type;
283
+ if (!marksType || !isArraySchemaType(marksType)) {
284
+ return void 0;
285
+ }
286
+ return arrayOf(marksType, schema, options);
287
+ }
242
288
  function arrayOf(arrayType, schema, options) {
243
289
  return arrayType.of.filter(type => isAssistSupported(type)).map(t => {
244
290
  return serializeMember(schema, t, t.name, options);
@@ -357,7 +403,111 @@ function SchemaEntry(_ref) {
357
403
  children: out
358
404
  });
359
405
  }
406
+ const MAX_DEPTH$1 = 6;
407
+ function getDocumentMembersFlat(doc, schemaType) {
408
+ if (!isDocumentSchemaType(schemaType)) {
409
+ console.error("Schema type is not a document");
410
+ return [];
411
+ }
412
+ return extractPaths(doc, schemaType, [], MAX_DEPTH$1);
413
+ }
414
+ function extractPaths(doc, schemaType, path, maxDepth) {
415
+ if (path.length >= maxDepth) {
416
+ return [];
417
+ }
418
+ return schemaType.fields.reduce((acc, field) => {
419
+ var _a, _b;
420
+ const fieldPath = [...path, field.name];
421
+ const fieldSchema = field.type;
422
+ const {
423
+ value
424
+ } = (_a = extractWithPath(pathToString(fieldPath), doc)[0]) != null ? _a : {};
425
+ if (!value) {
426
+ return acc;
427
+ }
428
+ const thisFieldWithPath = {
429
+ path: fieldPath,
430
+ name: field.name,
431
+ schemaType: fieldSchema,
432
+ value
433
+ };
434
+ if (fieldSchema.jsonType === "object") {
435
+ const innerFields = extractPaths(doc, fieldSchema, fieldPath, maxDepth);
436
+ return [...acc, thisFieldWithPath, ...innerFields];
437
+ } else if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some(item => "fields" in item)) {
438
+ const {
439
+ value: arrayValue
440
+ } = (_b = extractWithPath(pathToString(fieldPath), doc)[0]) != null ? _b : {};
441
+ let arrayPaths = [];
442
+ if (arrayValue == null ? void 0 : arrayValue.length) {
443
+ for (const item of arrayValue) {
444
+ const itemPath = [...fieldPath, {
445
+ _key: item._key
446
+ }];
447
+ let itemSchema = fieldSchema.of.find(t => t.name === item._type);
448
+ if (!item._type) {
449
+ itemSchema = fieldSchema.of[0];
450
+ console.warn("Array item is missing _type - using the first defined type in the array.of schema", {
451
+ itemPath,
452
+ item,
453
+ itemSchema
454
+ });
455
+ }
456
+ if (item._key && itemSchema) {
457
+ const innerFields = extractPaths(doc, itemSchema, itemPath, maxDepth);
458
+ const arrayMember = {
459
+ path: itemPath,
460
+ name: item._key,
461
+ schemaType: itemSchema,
462
+ value: item
463
+ };
464
+ arrayPaths = [...arrayPaths, arrayMember, ...innerFields];
465
+ }
466
+ }
467
+ }
468
+ return [...acc, thisFieldWithPath, ...arrayPaths];
469
+ }
470
+ return [...acc, thisFieldWithPath];
471
+ }, []);
472
+ }
473
+ const defaultLanguageOutputs = function (member, enclosingType, translateFromLanguageId, translateToLanguageIds) {
474
+ if (member.schemaType.jsonType === "object" && member.schemaType.name.startsWith("internationalizedArray")) {
475
+ const pathEnd = member.path.slice(-1);
476
+ const language = isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null;
477
+ return language === translateFromLanguageId ? translateToLanguageIds.map(translateToId => ({
478
+ id: translateToId,
479
+ outputPath: [...member.path.slice(0, -1), {
480
+ _key: translateToId
481
+ }]
482
+ })) : void 0;
483
+ }
484
+ if (enclosingType.jsonType === "object" && enclosingType.name.startsWith("locale")) {
485
+ return translateFromLanguageId === member.name ? translateToLanguageIds.map(translateToId => ({
486
+ id: translateToId,
487
+ outputPath: [...member.path.slice(0, -1), translateToId]
488
+ })) : void 0;
489
+ }
490
+ return void 0;
491
+ };
492
+ function getFieldLanguageMap(documentSchema, documentMembers, translateFromLanguageId, outputLanguageIds, langFn) {
493
+ var _a, _b, _c;
494
+ const translationMaps = [];
495
+ for (const member of documentMembers) {
496
+ const parentPath = member.path.slice(0, -1);
497
+ const enclosingType = (_b = (_a = documentMembers.find(m => pathToString(m.path) === pathToString(parentPath))) == null ? void 0 : _a.schemaType) != null ? _b : documentSchema;
498
+ const translations = (_c = langFn(member, enclosingType, translateFromLanguageId, outputLanguageIds)) == null ? void 0 : _c.filter(translation => translation.id !== translateFromLanguageId);
499
+ if (translations) {
500
+ translationMaps.push({
501
+ inputLanguageId: translateFromLanguageId,
502
+ inputPath: member.path,
503
+ outputs: translations
504
+ });
505
+ }
506
+ }
507
+ return translationMaps;
508
+ }
360
509
  const aiInspectorId = "ai-assistance";
510
+ const assistFormId = "assist";
361
511
  const preventDefault = ev => ev.preventDefault();
362
512
  function DocumentForm(props) {
363
513
  var _a;
@@ -453,7 +603,7 @@ function DocumentForm(props) {
453
603
  changed: formState.changed,
454
604
  focused: formState.focused,
455
605
  groups: formState.groups,
456
- id: "root",
606
+ id: assistFormId,
457
607
  members: formState.members,
458
608
  onChange,
459
609
  onFieldGroupSelect: onSetActiveFieldGroup,
@@ -551,7 +701,7 @@ function getFieldRefs(schemaType, parent) {
551
701
  };
552
702
  const fields = field.type.jsonType === "object" ? getFieldRefs(field.type, fieldRef, depth + 1) : [];
553
703
  const syntheticFields = field.type.jsonType === "array" ? getSyntheticFields(field.type, fieldRef, depth + 1) : [];
554
- if (!isAssistSupported(field.type, true)) {
704
+ if (!isAssistSupported(field.type)) {
555
705
  return [...fields, ...syntheticFields];
556
706
  }
557
707
  return [fieldRef, ...fields, ...syntheticFields];
@@ -578,7 +728,7 @@ function getSyntheticFields(schemaType, parent) {
578
728
  synthetic: true
579
729
  };
580
730
  const fields = itemType.jsonType === "object" ? getFieldRefs(itemType, fieldRef, depth + 1) : [];
581
- if (!isAssistSupported(itemType, true)) {
731
+ if (!isAssistSupported(itemType)) {
582
732
  return fields;
583
733
  }
584
734
  return [fieldRef, ...fields];
@@ -588,7 +738,7 @@ function getTypePath(doc, pathString) {
588
738
  if (!pathString) {
589
739
  return void 0;
590
740
  }
591
- const path = stringToPath(pathString);
741
+ const path = stringToPath$2(pathString);
592
742
  const currentPath = [];
593
743
  let valid = true;
594
744
  const syntheticPath = path.map(segment => {
@@ -667,7 +817,6 @@ function useStudioAssistDocument(_ref2) {
667
817
  } = _ref2;
668
818
  const documentTypeName = schemaType.name;
669
819
  const currentUser = useCurrentUser();
670
- const validation = useValidationStatus(publicId(documentId), schemaType.name).validation;
671
820
  const assistDocument = useDocumentState(assistDocumentId(documentTypeName), assistDocumentTypeName);
672
821
  const assistTasksStatus = useDocumentState(assistTasksStatusId(documentId != null ? documentId : ""), assistTasksStatusTypeName);
673
822
  const client = useClient({
@@ -692,7 +841,7 @@ function useStudioAssistDocument(_ref2) {
692
841
  return {
693
842
  ...assistField,
694
843
  tasks: tasks.filter(task => task.path === assistField.path),
695
- instructions: (_a2 = assistField.instructions) == null ? void 0 : _a2.filter(p => !p.userId || p.userId === (currentUser == null ? void 0 : currentUser.id)).map(instruction => asStudioInstruction(instruction, tasks, validation))
844
+ instructions: (_a2 = assistField.instructions) == null ? void 0 : _a2.filter(p => !p.userId || p.userId === (currentUser == null ? void 0 : currentUser.id)).map(instruction => asStudioInstruction(instruction, tasks))
696
845
  };
697
846
  });
698
847
  return typed({
@@ -707,21 +856,12 @@ function useStudioAssistDocument(_ref2) {
707
856
  }),
708
857
  fields
709
858
  });
710
- }, [assistDocument, assistTasksStatus, currentUser, validation]);
859
+ }, [assistDocument, assistTasksStatus, currentUser]);
711
860
  }
712
- function asStudioInstruction(instruction, run, validation) {
713
- var _a;
714
- const errors = validation.filter(marker => marker.level === "error");
715
- const fieldRefs = ((_a = instruction == null ? void 0 : instruction.prompt) != null ? _a : []).flatMap(block => {
716
- if (block._type === "block") {
717
- return block.children.filter(c => c._type === fieldReferenceTypeName);
718
- }
719
- return [];
720
- });
861
+ function asStudioInstruction(instruction, run) {
721
862
  return {
722
863
  ...instruction,
723
- tasks: run.filter(task => task.instructionKey === instruction._key).filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs),
724
- validation: errors.filter(marker => fieldRefs.map(r => r.path).filter(p => !!p).find(path => pathToString(marker.path) === path))
864
+ tasks: run.filter(task => task.instructionKey === instruction._key).filter(task => task.started && ( /* @__PURE__ */new Date()).getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs)
725
865
  };
726
866
  }
727
867
  function useInterval(ms) {
@@ -802,13 +942,13 @@ function InstructionTaskHistoryButton(props) {
802
942
  const statusDocId = assistTasksStatusId(documentId);
803
943
  const basePath = "".concat(typed("tasks"), '[_key=="').concat(taskKey, '"]');
804
944
  client.patch(statusDocId).set({
805
- ["".concat(basePath, ".").concat(typed("ended"))]: /* @__PURE__ */new Date().toISOString(),
945
+ ["".concat(basePath, ".").concat(typed("ended"))]: ( /* @__PURE__ */new Date()).toISOString(),
806
946
  ["".concat(basePath, ".").concat(typed("reason"))]: typed("aborted")
807
947
  }).commit().catch(console.error);
808
948
  }, [client, documentId]);
809
949
  const titledTasks = useMemo(() => {
810
950
  var _a2;
811
- const t = (_a2 = tasks == null ? void 0 : tasks.filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
951
+ const t = (_a2 = tasks == null ? void 0 : tasks.filter(task => task.started && ( /* @__PURE__ */new Date()).getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
812
952
  var _a3;
813
953
  const instruction = instructions == null ? void 0 : instructions.find(i => i._key === task.instructionKey);
814
954
  return {
@@ -875,11 +1015,10 @@ const TaskStatusButton = forwardRef(function TaskStatusButton2(props, ref) {
875
1015
  mode: "bleed",
876
1016
  onClick,
877
1017
  tone: hasErrors ? "critical" : void 0,
878
- fontSize: 1,
879
1018
  disabled,
880
1019
  ref,
881
1020
  selected,
882
- tooltip: TASK_STATUS_BUTTON_TOOLTIP_PROPS
1021
+ tooltipProps: TASK_STATUS_BUTTON_TOOLTIP_PROPS
883
1022
  });
884
1023
  });
885
1024
  function TaskList(props) {
@@ -966,6 +1105,54 @@ function useApiClient(customApiClient) {
966
1105
  });
967
1106
  return useMemo(() => customApiClient ? customApiClient(client) : client, [client, customApiClient]);
968
1107
  }
1108
+ function useTranslate(apiClient) {
1109
+ const [loading, setLoading] = useState(false);
1110
+ const user = useCurrentUser();
1111
+ const schema = useSchema();
1112
+ const types = useMemo(() => serializeSchema(schema, {
1113
+ leanFormat: true
1114
+ }), [schema]);
1115
+ const toast = useToast();
1116
+ const translate = useCallback(_ref4 => {
1117
+ let {
1118
+ documentId,
1119
+ languagePath,
1120
+ translatePath,
1121
+ fieldLanguageMap,
1122
+ conditionalMembers
1123
+ } = _ref4;
1124
+ setLoading(true);
1125
+ return apiClient.request({
1126
+ method: "POST",
1127
+ url: "/assist/tasks/translate/".concat(apiClient.config().dataset, "?projectId=").concat(apiClient.config().projectId),
1128
+ body: {
1129
+ documentId,
1130
+ types,
1131
+ languagePath,
1132
+ fieldLanguageMap,
1133
+ conditionalMembers,
1134
+ translatePath: translatePath.length === 0 ? documentRootKey : pathToString(translatePath),
1135
+ userId: user == null ? void 0 : user.id
1136
+ }
1137
+ }).catch(e => {
1138
+ toast.push({
1139
+ status: "error",
1140
+ title: "Translate failed",
1141
+ description: e.message
1142
+ });
1143
+ setLoading(false);
1144
+ throw e;
1145
+ }).finally(() => {
1146
+ setTimeout(() => {
1147
+ setLoading(false);
1148
+ }, 2e3);
1149
+ });
1150
+ }, [setLoading, apiClient, toast, user, types]);
1151
+ return useMemo(() => ({
1152
+ translate,
1153
+ loading
1154
+ }), [translate, loading]);
1155
+ }
969
1156
  function useGenerateCaption(apiClient) {
970
1157
  const [loading, setLoading] = useState(false);
971
1158
  const user = useCurrentUser();
@@ -974,11 +1161,11 @@ function useGenerateCaption(apiClient) {
974
1161
  leanFormat: true
975
1162
  }), [schema]);
976
1163
  const toast = useToast();
977
- const generateCaption = useCallback(_ref4 => {
1164
+ const generateCaption = useCallback(_ref5 => {
978
1165
  let {
979
1166
  path,
980
1167
  documentId
981
- } = _ref4;
1168
+ } = _ref5;
982
1169
  setLoading(true);
983
1170
  return apiClient.request({
984
1171
  method: "POST",
@@ -992,7 +1179,7 @@ function useGenerateCaption(apiClient) {
992
1179
  }).catch(e => {
993
1180
  toast.push({
994
1181
  status: "error",
995
- title: "Generate caption failed",
1182
+ title: "Generate image description failed",
996
1183
  description: e.message
997
1184
  });
998
1185
  setLoading(false);
@@ -1008,6 +1195,48 @@ function useGenerateCaption(apiClient) {
1008
1195
  loading
1009
1196
  }), [generateCaption, loading]);
1010
1197
  }
1198
+ function useGenerateImage(apiClient) {
1199
+ const [loading, setLoading] = useState(false);
1200
+ const user = useCurrentUser();
1201
+ const schema = useSchema();
1202
+ const types = useMemo(() => serializeSchema(schema, {
1203
+ leanFormat: true
1204
+ }), [schema]);
1205
+ const toast = useToast();
1206
+ const generateImage = useCallback(_ref6 => {
1207
+ let {
1208
+ path,
1209
+ documentId
1210
+ } = _ref6;
1211
+ setLoading(true);
1212
+ return apiClient.request({
1213
+ method: "POST",
1214
+ url: "/assist/tasks/generate-image/".concat(apiClient.config().dataset, "?projectId=").concat(apiClient.config().projectId),
1215
+ body: {
1216
+ path,
1217
+ documentId,
1218
+ types,
1219
+ userId: user == null ? void 0 : user.id
1220
+ }
1221
+ }).catch(e => {
1222
+ toast.push({
1223
+ status: "error",
1224
+ title: "Generate image from prompt failed",
1225
+ description: e.message
1226
+ });
1227
+ setLoading(false);
1228
+ throw e;
1229
+ }).finally(() => {
1230
+ setTimeout(() => {
1231
+ setLoading(false);
1232
+ }, 2e3);
1233
+ });
1234
+ }, [setLoading, apiClient, toast, user, types]);
1235
+ return useMemo(() => ({
1236
+ generateImage,
1237
+ loading
1238
+ }), [generateImage, loading]);
1239
+ }
1011
1240
  function useGetInstructStatus(apiClient) {
1012
1241
  const [loading, setLoading] = useState(true);
1013
1242
  const getInstructStatus = useCallback(async () => {
@@ -1197,8 +1426,8 @@ function RunInstructionProvider(props) {
1197
1426
  runInstructionRequest({
1198
1427
  ...request,
1199
1428
  instructionKey: instruction._key,
1200
- userTexts: Object.entries(inputs).map(_ref5 => {
1201
- let [key, value] = _ref5;
1429
+ userTexts: Object.entries(inputs).map(_ref7 => {
1430
+ let [key, value] = _ref7;
1202
1431
  return {
1203
1432
  blockKey: key,
1204
1433
  userInput: value
@@ -1211,8 +1440,8 @@ function RunInstructionProvider(props) {
1211
1440
  const open = !!runRequest;
1212
1441
  const runDisabled = useMemo(() => {
1213
1442
  var _a2, _b;
1214
- return ((_b = (_a2 = runRequest == null ? void 0 : runRequest.userInputBlocks) == null ? void 0 : _a2.length) != null ? _b : 0) > Object.entries(inputs).filter(_ref6 => {
1215
- let [, value] = _ref6;
1443
+ return ((_b = (_a2 = runRequest == null ? void 0 : runRequest.userInputBlocks) == null ? void 0 : _a2.length) != null ? _b : 0) > Object.entries(inputs).filter(_ref8 => {
1444
+ let [, value] = _ref8;
1216
1445
  return !!value;
1217
1446
  }).length;
1218
1447
  }, [runRequest == null ? void 0 : runRequest.userInputBlocks, inputs]);
@@ -1323,29 +1552,37 @@ function getAssistableDocId(documentSchemaType, documentId) {
1323
1552
  return documentSchemaType.liveEdit ? baseId : "drafts.".concat(baseId);
1324
1553
  }
1325
1554
  function useRequestRunInstruction(args) {
1326
- const {
1327
- documentOnChange,
1328
- isDocAssistable: isDocAssistable2
1329
- } = args;
1330
1555
  const {
1331
1556
  runInstruction,
1332
1557
  instructionLoading
1333
1558
  } = useRunInstruction();
1334
- const [queuedTask, setQueuedTask] = useState(void 0);
1335
- useEffect(() => {
1336
- if (queuedTask && isDocAssistable2) {
1337
- runInstruction(queuedTask);
1338
- setQueuedTask(void 0);
1339
- }
1340
- }, [queuedTask, isDocAssistable2, runInstruction]);
1559
+ const requestRunInstruction = useDraftDelayedTask({
1560
+ ...args,
1561
+ task: runInstruction
1562
+ });
1341
1563
  return {
1342
1564
  instructionLoading,
1343
- requestRunInstruction: useCallback(task => {
1344
- documentOnChange(PatchEvent.from([unset(["_force_document_creation"])]));
1345
- setQueuedTask(task);
1346
- }, [setQueuedTask, documentOnChange])
1565
+ requestRunInstruction
1347
1566
  };
1348
1567
  }
1568
+ function useDraftDelayedTask(args) {
1569
+ const {
1570
+ documentOnChange,
1571
+ isDocAssistable: isDocAssistable2,
1572
+ task
1573
+ } = args;
1574
+ const [queuedArgs, setQueuedArgs] = useState(void 0);
1575
+ useEffect(() => {
1576
+ if (queuedArgs && isDocAssistable2) {
1577
+ task(queuedArgs);
1578
+ setQueuedArgs(void 0);
1579
+ }
1580
+ }, [queuedArgs, isDocAssistable2, task]);
1581
+ return useCallback(taskArgs => {
1582
+ documentOnChange(PatchEvent.from([unset(["_force_document_creation"])]));
1583
+ setQueuedArgs(taskArgs);
1584
+ }, [setQueuedArgs, documentOnChange]);
1585
+ }
1349
1586
  const SparklesIllustration = styled(SparklesIcon)({
1350
1587
  fontSize: "3.125em",
1351
1588
  "& path": {
@@ -1577,7 +1814,7 @@ function useSelectedSchema(fieldPath, documentSchema) {
1577
1814
  if (fieldPath === documentRootKey) {
1578
1815
  return documentSchema;
1579
1816
  }
1580
- const path = stringToPath(fieldPath);
1817
+ const path = stringToPath$2(fieldPath);
1581
1818
  let currentSchema = documentSchema;
1582
1819
  for (let i = 0; i < path.length; i++) {
1583
1820
  const segment = path[i];
@@ -1596,13 +1833,13 @@ function useSelectedSchema(fieldPath, documentSchema) {
1596
1833
  return currentSchema;
1597
1834
  }, [documentSchema, fieldPath]);
1598
1835
  }
1599
- function FieldsInitializer(_ref7) {
1836
+ function FieldsInitializer(_ref9) {
1600
1837
  let {
1601
1838
  pathKey,
1602
1839
  activePath,
1603
1840
  fieldExists,
1604
1841
  onChange
1605
- } = _ref7;
1842
+ } = _ref9;
1606
1843
  const initialized = useRef(false);
1607
1844
  useEffect(() => {
1608
1845
  if (initialized.current || fieldExists || activePath || !pathKey) {
@@ -1633,7 +1870,7 @@ function FieldAutocomplete(props) {
1633
1870
  return getFieldRefs(schemaType);
1634
1871
  }, [schemaType, includeDocument]);
1635
1872
  const currentField = useMemo(() => fieldRefs.find(f => f.key === fieldPath), [fieldPath, fieldRefs]);
1636
- const autocompleteOptions = useMemo(() => fieldRefs.filter(field => filter ? filter(field) : true).map(field => ({
1873
+ const autocompleteOptions = useMemo(() => fieldRefs.filter(field => filter ? filter(field) : true).filter(f => !isType(f.schemaType, "reference")).map(field => ({
1637
1874
  value: field.key,
1638
1875
  field
1639
1876
  })), [fieldRefs, filter]);
@@ -1746,6 +1983,78 @@ function FieldTitle(props) {
1746
1983
  })
1747
1984
  });
1748
1985
  }
1986
+ const MAX_DEPTH = 8;
1987
+ function getConditionalMembers(docState) {
1988
+ const doc = {
1989
+ path: "",
1990
+ hidden: false,
1991
+ readOnly: !!docState.readOnly,
1992
+ conditional: typeof docState.schemaType.hidden === "function"
1993
+ };
1994
+ return [doc, ...extractConditionalPaths(docState, MAX_DEPTH)].filter(v => v.conditional).map(_ref10 => {
1995
+ let {
1996
+ conditional,
1997
+ ...state
1998
+ } = _ref10;
1999
+ return {
2000
+ ...state
2001
+ };
2002
+ });
2003
+ }
2004
+ function isConditional(schemaType) {
2005
+ return typeof schemaType.hidden === "function" || typeof schemaType.readOnly === "function";
2006
+ }
2007
+ function conditionalState(memberState) {
2008
+ return {
2009
+ path: pathToString(memberState.path),
2010
+ readOnly: !!memberState.readOnly,
2011
+ hidden: false,
2012
+ // if its in members, its not hidden
2013
+ conditional: isConditional(memberState.schemaType)
2014
+ };
2015
+ }
2016
+ function extractConditionalPaths(node, maxDepth) {
2017
+ if (node.path.length >= maxDepth) {
2018
+ return [];
2019
+ }
2020
+ return node.members.reduce((acc, member) => {
2021
+ var _a, _b;
2022
+ if (member.kind === "error") {
2023
+ return acc;
2024
+ }
2025
+ if (member.kind === "field") {
2026
+ const schemaType = member.field.schemaType;
2027
+ if (schemaType.jsonType === "object") {
2028
+ const innerFields = member.field.readOnly ? [] : extractConditionalPaths(member.field, maxDepth);
2029
+ return [...acc, conditionalState(member.field), ...innerFields];
2030
+ } else if (schemaType.jsonType === "array") {
2031
+ const array = member.field;
2032
+ let arrayPaths = [];
2033
+ const isObjectsArray = array.members.some(m => m.kind === "item" && isObjectSchemaType(m.item.schemaType));
2034
+ if (!array.readOnly) {
2035
+ for (const arrayMember of array.members) {
2036
+ if (arrayMember.kind === "error") {
2037
+ continue;
2038
+ }
2039
+ const innerFields = isObjectsArray && !arrayMember.item.readOnly ? extractConditionalPaths(arrayMember.item, maxDepth) : [];
2040
+ arrayPaths = [...arrayPaths, conditionalState(arrayMember.item), ...innerFields];
2041
+ }
2042
+ }
2043
+ return [...acc, conditionalState(array), ...arrayPaths];
2044
+ }
2045
+ return [...acc, conditionalState(member.field)];
2046
+ } else if (member.kind === "fieldSet") {
2047
+ const conditionalFieldset = !!((_b = (_a = node.schemaType) == null ? void 0 : _a.fieldsets) == null ? void 0 : _b.some(f => !f.single && f.name === member.fieldSet.name && typeof f.hidden === "function"));
2048
+ const innerFields = extractConditionalPaths(member.fieldSet, maxDepth).map(f => ({
2049
+ ...f,
2050
+ // if fieldset is conditional, visible fields must also be considered conditional
2051
+ conditional: conditionalFieldset != null ? conditionalFieldset : f.conditional
2052
+ }));
2053
+ return [...acc, ...innerFields];
2054
+ }
2055
+ return acc;
2056
+ }, []);
2057
+ }
1749
2058
  var __freeze$4 = Object.freeze;
1750
2059
  var __defProp$4 = Object.defineProperty;
1751
2060
  var __template$4 = (cooked, raw) => __freeze$4(__defProp$4(cooked, "raw", {
@@ -1885,12 +2194,15 @@ function AssistInspector(props) {
1885
2194
  documentType,
1886
2195
  value: docValue,
1887
2196
  schemaType,
1888
- onChange: documentOnChange
2197
+ onChange: documentOnChange,
2198
+ formState
1889
2199
  } = documentPane;
1890
2200
  const {
1891
2201
  published,
1892
2202
  draft
1893
2203
  } = useEditState(documentId, documentType, "low");
2204
+ const formStateRef = useRef(formState);
2205
+ formStateRef.current = formState;
1894
2206
  const assistableDocId = getAssistableDocId(schemaType, documentId);
1895
2207
  const {
1896
2208
  instructionLoading,
@@ -1944,7 +2256,8 @@ function AssistInspector(props) {
1944
2256
  path: pathKey,
1945
2257
  typePath,
1946
2258
  assistDocumentId: assistDocumentId(documentType),
1947
- instruction
2259
+ instruction,
2260
+ conditionalMembers: formStateRef.current ? getConditionalMembers(formStateRef.current) : []
1948
2261
  }), [pathKey, instruction, typePath, documentType, assistableDocId, requestRunInstruction]);
1949
2262
  const Region = useCallback(_props => {
1950
2263
  return /* @__PURE__ */jsx("div", {
@@ -2130,10 +2443,10 @@ const assistInspector = {
2130
2443
  showAsAction: false
2131
2444
  }),
2132
2445
  component: AssistInspectorWrapper,
2133
- onClose(_ref8) {
2446
+ onClose(_ref11) {
2134
2447
  let {
2135
2448
  params
2136
- } = _ref8;
2449
+ } = _ref11;
2137
2450
  return {
2138
2451
  params: typed({
2139
2452
  ...params,
@@ -2161,11 +2474,11 @@ function useAssistPresence(path, showFocusWithin) {
2161
2474
  const activePresence = (_b = (_a = tasks == null ? void 0 : tasks.filter(task => !task.ended)) == null ? void 0 : _a.flatMap(task => {
2162
2475
  var _a2;
2163
2476
  return (_a2 = task.presence) != null ? _a2 : [];
2164
- })) == null ? void 0 : _b.filter(p => p.started && /* @__PURE__ */new Date().getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs).filter(presence => {
2477
+ })) == null ? void 0 : _b.filter(p => p.started && ( /* @__PURE__ */new Date()).getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs).filter(presence => {
2165
2478
  if (!presence.path || !path.length) {
2166
2479
  return false;
2167
2480
  }
2168
- const statusPath = stringToPath(presence.path);
2481
+ const statusPath = stringToPath$2(presence.path);
2169
2482
  if (!showFocusWithin && statusPath.length !== path.length) {
2170
2483
  return false;
2171
2484
  }
@@ -2195,7 +2508,7 @@ function aiPresence(presence, path, title) {
2195
2508
  },
2196
2509
  path,
2197
2510
  sessionId: "not-available",
2198
- lastActiveAt: (_a = presence == null ? void 0 : presence.started) != null ? _a : /* @__PURE__ */new Date().toISOString()
2511
+ lastActiveAt: (_a = presence == null ? void 0 : presence.started) != null ? _a : ( /* @__PURE__ */new Date()).toISOString()
2199
2512
  };
2200
2513
  }
2201
2514
  var __freeze$3 = Object.freeze;
@@ -2206,11 +2519,11 @@ var __template$3 = (cooked, raw) => __freeze$3(__defProp$3(cooked, "raw", {
2206
2519
  var _a$3, _b$1;
2207
2520
  const fadeIn = keyframes(_a$3 || (_a$3 = __template$3(["\n 0% {\n opacity: 0;\n transform: scale(0.75);\n }\n 40% {\n opacity: 0;\n transform: scale(0.75);\n }\n 100% {\n opacity: 1;\n transform: scale(1);\n }\n"])));
2208
2521
  const FadeInDiv = styled.div(_b$1 || (_b$1 = __template$3(["\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n"])), fadeIn);
2209
- const FadeInContent = forwardRef(function FadeInContent2(_ref9, ref) {
2522
+ const FadeInContent = forwardRef(function FadeInContent2(_ref12, ref) {
2210
2523
  let {
2211
2524
  children,
2212
2525
  durationMs = 250
2213
- } = _ref9;
2526
+ } = _ref12;
2214
2527
  return /* @__PURE__ */jsx(FadeInDiv, {
2215
2528
  ref,
2216
2529
  style: {
@@ -2222,47 +2535,47 @@ const FadeInContent = forwardRef(function FadeInContent2(_ref9, ref) {
2222
2535
  const purple = {
2223
2536
  "50": {
2224
2537
  title: "Purple 50",
2225
- hex: "#f8e9fe"
2538
+ hex: "#f8f5ff"
2226
2539
  },
2227
2540
  "100": {
2228
2541
  title: "Purple 100",
2229
- hex: "#f2d3fe"
2542
+ hex: "#f1ebff"
2230
2543
  },
2231
2544
  "200": {
2232
2545
  title: "Purple 200",
2233
- hex: "#e6a7fd"
2546
+ hex: "#ece1fe"
2234
2547
  },
2235
2548
  "300": {
2236
2549
  title: "Purple 300",
2237
- hex: "#d97bfd"
2550
+ hex: "#ccb1fc"
2238
2551
  },
2239
2552
  "400": {
2240
2553
  title: "Purple 400",
2241
- hex: "#cd4efc"
2554
+ hex: "#b087f7"
2242
2555
  },
2243
2556
  "500": {
2244
2557
  title: "Purple 500",
2245
- hex: "#c123fc"
2558
+ hex: "#8f57ef"
2246
2559
  },
2247
2560
  "600": {
2248
2561
  title: "Purple 600",
2249
- hex: "#9d1fcd"
2562
+ hex: "#721fe5"
2250
2563
  },
2251
2564
  "700": {
2252
2565
  title: "Purple 700",
2253
- hex: "#7a1b9e"
2566
+ hex: "#4c1a9e"
2254
2567
  },
2255
2568
  "800": {
2256
2569
  title: "Purple 800",
2257
- hex: "#56186f"
2570
+ hex: "#2f1862"
2258
2571
  },
2259
2572
  "900": {
2260
2573
  title: "Purple 900",
2261
- hex: "#331440"
2574
+ hex: "#23173f"
2262
2575
  },
2263
2576
  "950": {
2264
2577
  title: "Purple 950",
2265
- hex: "#211229"
2578
+ hex: "#181128"
2266
2579
  }
2267
2580
  };
2268
2581
  var __freeze$2 = Object.freeze;
@@ -2313,7 +2626,11 @@ function AssistAvatar(props) {
2313
2626
  style: {
2314
2627
  color: "inherit"
2315
2628
  },
2316
- children: /* @__PURE__ */jsx(SparklesIcon, {})
2629
+ children: /* @__PURE__ */jsx(SparklesIcon, {
2630
+ style: {
2631
+ color: "inherit"
2632
+ }
2633
+ })
2317
2634
  })
2318
2635
  })]
2319
2636
  });
@@ -2459,7 +2776,7 @@ function AssistFieldWrapper(props) {
2459
2776
  if (!isSupported || schemaType.name.startsWith("sanity.") || schemaType.name === contextDocumentTypeName) {
2460
2777
  return props.renderDefault(props);
2461
2778
  }
2462
- if (!isType(props.schemaType, "document") && props.inputId !== "root") {
2779
+ if (!isType(props.schemaType, "document") && props.inputId !== "root" && props.inputId !== assistFormId) {
2463
2780
  return /* @__PURE__ */jsx(AssistField, {
2464
2781
  ...props,
2465
2782
  children: props.children
@@ -2479,15 +2796,16 @@ function AssistField(props) {
2479
2796
  showOnboarding,
2480
2797
  dismissOnboarding
2481
2798
  } = useOnboardingFeature(fieldOnboardingKey);
2799
+ const singlePresence = presence[0];
2482
2800
  const actions = /* @__PURE__ */jsxs(Flex, {
2483
2801
  gap: 2,
2484
2802
  align: "center",
2485
2803
  justify: "space-between",
2486
- children: [presence.map(pre => /* @__PURE__ */jsx(Box, {
2804
+ children: [singlePresence && /* @__PURE__ */jsx(Box, {
2487
2805
  children: /* @__PURE__ */jsx(AiFieldPresence, {
2488
- presence: pre
2489
- }, pre.lastActiveAt)
2490
- }, pre.user.id)), isFirstAssisted && showOnboarding && /* @__PURE__ */jsx(AssistOnboardingPopover, {
2806
+ presence: singlePresence
2807
+ })
2808
+ }), isFirstAssisted && showOnboarding && /* @__PURE__ */jsx(AssistOnboardingPopover, {
2491
2809
  dismiss: dismissOnboarding
2492
2810
  })]
2493
2811
  });
@@ -2959,7 +3277,6 @@ function AssistConnectorsOverlay(props) {
2959
3277
  zIndex: 150
2960
3278
  // zIndex,
2961
3279
  },
2962
-
2963
3280
  children: connectors.map(connector => /* @__PURE__ */jsx(ConnectorPath, {
2964
3281
  from: connector.from,
2965
3282
  options,
@@ -2968,253 +3285,1464 @@ function AssistConnectorsOverlay(props) {
2968
3285
  }), DEBUG]
2969
3286
  });
2970
3287
  }
2971
- const legacyAssistDocumentIdPrefix = "sanity.ai.";
2972
- const legacyAssistDocumentTypeName = "sanity.ai.docType";
2973
- const legacyContextDocumentTypeName = "ai.instruction.context";
2974
- const legacyAssistStatusDocumentTypeName = "sanity.ai.instructionStatus";
2975
- const NO_ASSIST_DOCS = [];
2976
- const NO_CONTEXT_DOCS = [];
2977
- const NO_IDS = [];
2978
- function AlphaMigration() {
2979
- const [alphaAssistDocs, setAlphaAssistDocs] = useState(NO_ASSIST_DOCS);
2980
- const [contextDocs, setContextDocs] = useState(NO_CONTEXT_DOCS);
2981
- const [staleStatusDocIds, setStaleStatusDocs] = useState(NO_IDS);
2982
- const [error, setError] = useState(void 0);
2983
- const [progress, setProgress] = useState(void 0);
2984
- const toast = useToast();
2985
- const client = useClient({
2986
- apiVersion: "2023-06-01"
2987
- });
2988
- useEffect(() => {
2989
- let canUpdate = true;
2990
- client.fetch('\n {\n "assistDocs": *[_type=="'.concat(legacyAssistDocumentTypeName, '"],\n "staleStatusDocIds": *[_type=="').concat(legacyAssistStatusDocumentTypeName, '"]._id,\n "contextDocs": *[_type=="').concat(legacyContextDocumentTypeName, '"],\n }\n ')).then(result => {
2991
- var _a, _b, _c;
2992
- if (!canUpdate || !result) {
2993
- return;
2994
- }
2995
- setAlphaAssistDocs((_a = result == null ? void 0 : result.assistDocs) != null ? _a : NO_ASSIST_DOCS);
2996
- setStaleStatusDocs((_b = result == null ? void 0 : result.staleStatusDocIds) != null ? _b : NO_IDS);
2997
- setContextDocs((_c = result == null ? void 0 : result.contextDocs) != null ? _c : NO_CONTEXT_DOCS);
2998
- });
2999
- return () => {
3000
- canUpdate = false;
3001
- };
3002
- }, [client, setAlphaAssistDocs, setStaleStatusDocs, setContextDocs]);
3003
- const convert = useCallback(async () => {
3004
- try {
3005
- setProgress(1e-4);
3006
- const tasks = [() => convertContextDocs(client, contextDocs), subtaskProgress => deleteDocs(client, staleStatusDocIds, subtaskProgress), subtaskProgress => convertDocs(client, alphaAssistDocs, subtaskProgress), subtaskProgress => deleteDocs(client, contextDocs.map(d => d._id), subtaskProgress)];
3007
- const taskSize = 1 / tasks.length;
3008
- for (let i = 0; i < tasks.length; i++) {
3009
- const startProgress = i / tasks.length;
3010
- await tasks[i](subProgress => setProgress(startProgress + subProgress * taskSize));
3011
- setProgress((i + 1) / tasks.length);
3012
- }
3013
- setProgress(1);
3014
- setAlphaAssistDocs(NO_ASSIST_DOCS);
3015
- setContextDocs(NO_CONTEXT_DOCS);
3016
- setStaleStatusDocs(NO_IDS);
3017
- toast.push({
3018
- title: "Converted instructions to new format.",
3019
- status: "success",
3020
- closable: true
3021
- });
3022
- } catch (e) {
3023
- console.error(e);
3024
- toast.push({
3025
- title: "An error occurred",
3026
- status: "error",
3027
- closable: true
3028
- });
3029
- setError(e);
3030
- setProgress(void 0);
3288
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3289
+ function getDefaultExportFromCjs(x) {
3290
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3291
+ }
3292
+
3293
+ /**
3294
+ * Checks if `value` is classified as an `Array` object.
3295
+ *
3296
+ * @static
3297
+ * @memberOf _
3298
+ * @since 0.1.0
3299
+ * @category Lang
3300
+ * @param {*} value The value to check.
3301
+ * @returns {boolean} Returns `true` if `value` is an array, else `false`.
3302
+ * @example
3303
+ *
3304
+ * _.isArray([1, 2, 3]);
3305
+ * // => true
3306
+ *
3307
+ * _.isArray(document.body.children);
3308
+ * // => false
3309
+ *
3310
+ * _.isArray('abc');
3311
+ * // => false
3312
+ *
3313
+ * _.isArray(_.noop);
3314
+ * // => false
3315
+ */
3316
+
3317
+ var isArray$3 = Array.isArray;
3318
+ var isArray_1 = isArray$3;
3319
+
3320
+ /** Detect free variable `global` from Node.js. */
3321
+
3322
+ var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
3323
+ var _freeGlobal = freeGlobal$1;
3324
+ var freeGlobal = _freeGlobal;
3325
+
3326
+ /** Detect free variable `self`. */
3327
+ var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
3328
+
3329
+ /** Used as a reference to the global object. */
3330
+ var root$3 = freeGlobal || freeSelf || Function('return this')();
3331
+ var _root = root$3;
3332
+ var root$2 = _root;
3333
+
3334
+ /** Built-in value references. */
3335
+ var Symbol$3 = root$2.Symbol;
3336
+ var _Symbol = Symbol$3;
3337
+ var Symbol$2 = _Symbol;
3338
+
3339
+ /** Used for built-in method references. */
3340
+ var objectProto$4 = Object.prototype;
3341
+
3342
+ /** Used to check objects for own properties. */
3343
+ var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
3344
+
3345
+ /**
3346
+ * Used to resolve the
3347
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
3348
+ * of values.
3349
+ */
3350
+ var nativeObjectToString$1 = objectProto$4.toString;
3351
+
3352
+ /** Built-in value references. */
3353
+ var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : undefined;
3354
+
3355
+ /**
3356
+ * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
3357
+ *
3358
+ * @private
3359
+ * @param {*} value The value to query.
3360
+ * @returns {string} Returns the raw `toStringTag`.
3361
+ */
3362
+ function getRawTag$1(value) {
3363
+ var isOwn = hasOwnProperty$3.call(value, symToStringTag$1),
3364
+ tag = value[symToStringTag$1];
3365
+ try {
3366
+ value[symToStringTag$1] = undefined;
3367
+ var unmasked = true;
3368
+ } catch (e) {}
3369
+ var result = nativeObjectToString$1.call(value);
3370
+ if (unmasked) {
3371
+ if (isOwn) {
3372
+ value[symToStringTag$1] = tag;
3373
+ } else {
3374
+ delete value[symToStringTag$1];
3031
3375
  }
3032
- }, [contextDocs, client, alphaAssistDocs, staleStatusDocIds, setProgress, toast]);
3033
- if ((alphaAssistDocs.length || staleStatusDocIds.length || contextDocs.length) && (!progress || progress < 1)) {
3034
- return /* @__PURE__ */jsx(Dialog, {
3035
- id: "outdated-assist-docs",
3036
- header: pluginTitle,
3037
- children: /* @__PURE__ */jsx(Card, {
3038
- padding: 3,
3039
- children: /* @__PURE__ */jsxs(Stack, {
3040
- space: 4,
3041
- style: {
3042
- maxWidth: 500
3043
- },
3044
- children: [/* @__PURE__ */jsxs(Text, {
3045
- size: 1,
3046
- children: ["It seems like this workspace contains documents from an", " ", /* @__PURE__ */jsxs("strong", {
3047
- children: ["older version of ", pluginTitle]
3048
- }), "."]
3049
- }), /* @__PURE__ */jsx(Text, {
3050
- size: 1,
3051
- children: "Cleanup is required."
3052
- }), error ? /* @__PURE__ */jsxs(Card, {
3053
- padding: 2,
3054
- tone: "critical",
3055
- border: true,
3056
- children: [/* @__PURE__ */jsx(Text, {
3057
- size: 1,
3058
- children: "An error occurred. See console for details."
3059
- }), " "]
3060
- }) : null, /* @__PURE__ */jsx(Button, {
3061
- icon: progress ? /* @__PURE__ */jsx(Box, {
3062
- style: {
3063
- marginTop: 5
3064
- },
3065
- children: /* @__PURE__ */jsx(Spinner, {})
3066
- }) : CheckmarkIcon,
3067
- disabled: !!progress,
3068
- text: progress ? "".concat(Math.floor(progress * 100), "%") : "Ok, convert to new format!",
3069
- tone: "primary",
3070
- onClick: convert
3071
- })]
3072
- })
3073
- })
3074
- });
3075
3376
  }
3076
- return null;
3377
+ return result;
3077
3378
  }
3078
- async function deleteDocs(client, ids, updateProgress) {
3079
- const chunkSize = 50;
3080
- for (let i = 0; i < ids.length; i += chunkSize) {
3081
- const progressCount = Math.min(ids.length, i + chunkSize);
3082
- const chunk = ids.slice(i, progressCount);
3083
- const trans = client.transaction();
3084
- chunk.forEach(id => trans.delete(id));
3085
- await trans.commit();
3086
- updateProgress(progressCount / ids.length);
3379
+ var _getRawTag = getRawTag$1;
3380
+
3381
+ /** Used for built-in method references. */
3382
+
3383
+ var objectProto$3 = Object.prototype;
3384
+
3385
+ /**
3386
+ * Used to resolve the
3387
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
3388
+ * of values.
3389
+ */
3390
+ var nativeObjectToString = objectProto$3.toString;
3391
+
3392
+ /**
3393
+ * Converts `value` to a string using `Object.prototype.toString`.
3394
+ *
3395
+ * @private
3396
+ * @param {*} value The value to convert.
3397
+ * @returns {string} Returns the converted string.
3398
+ */
3399
+ function objectToString$1(value) {
3400
+ return nativeObjectToString.call(value);
3401
+ }
3402
+ var _objectToString = objectToString$1;
3403
+ var Symbol$1 = _Symbol,
3404
+ getRawTag = _getRawTag,
3405
+ objectToString = _objectToString;
3406
+
3407
+ /** `Object#toString` result references. */
3408
+ var nullTag = '[object Null]',
3409
+ undefinedTag = '[object Undefined]';
3410
+
3411
+ /** Built-in value references. */
3412
+ var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
3413
+
3414
+ /**
3415
+ * The base implementation of `getTag` without fallbacks for buggy environments.
3416
+ *
3417
+ * @private
3418
+ * @param {*} value The value to query.
3419
+ * @returns {string} Returns the `toStringTag`.
3420
+ */
3421
+ function baseGetTag$2(value) {
3422
+ if (value == null) {
3423
+ return value === undefined ? undefinedTag : nullTag;
3087
3424
  }
3425
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
3088
3426
  }
3089
- async function convertContextDocs(client, docs) {
3090
- const trans = client.transaction();
3091
- for (const doc of docs) {
3092
- const {
3093
- _id,
3094
- _type,
3095
- ...rest
3096
- } = doc;
3097
- trans.createOrReplace({
3098
- ...rest,
3099
- _id: "port.".concat(_id),
3100
- _alphaId: _id,
3101
- _type: contextDocumentTypeName
3102
- });
3427
+ var _baseGetTag = baseGetTag$2;
3428
+
3429
+ /**
3430
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
3431
+ * and has a `typeof` result of "object".
3432
+ *
3433
+ * @static
3434
+ * @memberOf _
3435
+ * @since 4.0.0
3436
+ * @category Lang
3437
+ * @param {*} value The value to check.
3438
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
3439
+ * @example
3440
+ *
3441
+ * _.isObjectLike({});
3442
+ * // => true
3443
+ *
3444
+ * _.isObjectLike([1, 2, 3]);
3445
+ * // => true
3446
+ *
3447
+ * _.isObjectLike(_.noop);
3448
+ * // => false
3449
+ *
3450
+ * _.isObjectLike(null);
3451
+ * // => false
3452
+ */
3453
+
3454
+ function isObjectLike$1(value) {
3455
+ return value != null && typeof value == 'object';
3456
+ }
3457
+ var isObjectLike_1 = isObjectLike$1;
3458
+ var baseGetTag$1 = _baseGetTag,
3459
+ isObjectLike = isObjectLike_1;
3460
+
3461
+ /** `Object#toString` result references. */
3462
+ var symbolTag = '[object Symbol]';
3463
+
3464
+ /**
3465
+ * Checks if `value` is classified as a `Symbol` primitive or object.
3466
+ *
3467
+ * @static
3468
+ * @memberOf _
3469
+ * @since 4.0.0
3470
+ * @category Lang
3471
+ * @param {*} value The value to check.
3472
+ * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
3473
+ * @example
3474
+ *
3475
+ * _.isSymbol(Symbol.iterator);
3476
+ * // => true
3477
+ *
3478
+ * _.isSymbol('abc');
3479
+ * // => false
3480
+ */
3481
+ function isSymbol$3(value) {
3482
+ return typeof value == 'symbol' || isObjectLike(value) && baseGetTag$1(value) == symbolTag;
3483
+ }
3484
+ var isSymbol_1 = isSymbol$3;
3485
+ var isArray$2 = isArray_1,
3486
+ isSymbol$2 = isSymbol_1;
3487
+
3488
+ /** Used to match property names within property paths. */
3489
+ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
3490
+ reIsPlainProp = /^\w*$/;
3491
+
3492
+ /**
3493
+ * Checks if `value` is a property name and not a property path.
3494
+ *
3495
+ * @private
3496
+ * @param {*} value The value to check.
3497
+ * @param {Object} [object] The object to query keys on.
3498
+ * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
3499
+ */
3500
+ function isKey$1(value, object) {
3501
+ if (isArray$2(value)) {
3502
+ return false;
3103
3503
  }
3104
- await trans.commit();
3105
- }
3106
- async function convertDocs(client, docs, updateProgress) {
3107
- const chunkSize = 10;
3108
- for (let i = 0; i < docs.length; i += chunkSize) {
3109
- const progressCount = Math.min(docs.length, i + chunkSize);
3110
- const chunk = docs.slice(i, progressCount);
3111
- const trans = client.transaction();
3112
- const contextDocs = await client.fetch('*[_type=="'.concat(contextDocumentTypeName, '" && _alphaId != null]{_id, _alphaId}'));
3113
- chunk.forEach(oldDoc => {
3114
- var _a;
3115
- const documentType = oldDoc._id.replace(new RegExp("^(".concat(legacyAssistDocumentIdPrefix, "|").concat(assistDocumentIdPrefix, ")")), "");
3116
- const id = assistDocumentId(documentType);
3117
- const fields = ((_a = oldDoc.fields) != null ? _a : []).filter(field => {
3118
- var _a2;
3119
- return (_a2 = field.instructions) == null ? void 0 : _a2.length;
3120
- }).map(oldField => {
3121
- var _a2;
3122
- const instructions = ((_a2 = oldField.instructions) != null ? _a2 : []).map(inst => {
3123
- var _a3;
3124
- const prompt = ((_a3 = inst.prompt) != null ? _a3 : []).map(block => {
3125
- return mapBlock(block, contextDocs);
3126
- });
3127
- return {
3128
- ...inst,
3129
- _type: instructionTypeName,
3130
- prompt
3131
- };
3132
- });
3133
- return {
3134
- ...oldField,
3135
- _type: assistFieldTypeName,
3136
- instructions
3137
- };
3138
- });
3139
- if (fields.length) {
3140
- trans.createOrReplace({
3141
- _id: id,
3142
- _type: assistDocumentTypeName,
3143
- fields
3144
- });
3145
- }
3146
- trans.delete(oldDoc._id);
3147
- });
3148
- await trans.commit();
3149
- updateProgress(progressCount / docs.length);
3504
+ var type = typeof value;
3505
+ if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol$2(value)) {
3506
+ return true;
3150
3507
  }
3508
+ return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
3151
3509
  }
3152
- function isFieldRef(block) {
3153
- return block._type === "sanity.ai.prompt.fieldRef";
3154
- }
3155
- function isContext(block) {
3156
- return block._type === "sanity.ai.prompt.context";
3157
- }
3158
- function isUserInput(block) {
3159
- return block._type === "sanity.ai.prompt.userInput";
3510
+ var _isKey = isKey$1;
3511
+
3512
+ /**
3513
+ * Checks if `value` is the
3514
+ * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
3515
+ * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
3516
+ *
3517
+ * @static
3518
+ * @memberOf _
3519
+ * @since 0.1.0
3520
+ * @category Lang
3521
+ * @param {*} value The value to check.
3522
+ * @returns {boolean} Returns `true` if `value` is an object, else `false`.
3523
+ * @example
3524
+ *
3525
+ * _.isObject({});
3526
+ * // => true
3527
+ *
3528
+ * _.isObject([1, 2, 3]);
3529
+ * // => true
3530
+ *
3531
+ * _.isObject(_.noop);
3532
+ * // => true
3533
+ *
3534
+ * _.isObject(null);
3535
+ * // => false
3536
+ */
3537
+
3538
+ function isObject$2(value) {
3539
+ var type = typeof value;
3540
+ return value != null && (type == 'object' || type == 'function');
3160
3541
  }
3161
- function isSpan(block) {
3162
- return block._type === "span";
3542
+ var isObject_1 = isObject$2;
3543
+ var baseGetTag = _baseGetTag,
3544
+ isObject$1 = isObject_1;
3545
+
3546
+ /** `Object#toString` result references. */
3547
+ var asyncTag = '[object AsyncFunction]',
3548
+ funcTag = '[object Function]',
3549
+ genTag = '[object GeneratorFunction]',
3550
+ proxyTag = '[object Proxy]';
3551
+
3552
+ /**
3553
+ * Checks if `value` is classified as a `Function` object.
3554
+ *
3555
+ * @static
3556
+ * @memberOf _
3557
+ * @since 0.1.0
3558
+ * @category Lang
3559
+ * @param {*} value The value to check.
3560
+ * @returns {boolean} Returns `true` if `value` is a function, else `false`.
3561
+ * @example
3562
+ *
3563
+ * _.isFunction(_);
3564
+ * // => true
3565
+ *
3566
+ * _.isFunction(/abc/);
3567
+ * // => false
3568
+ */
3569
+ function isFunction$1(value) {
3570
+ if (!isObject$1(value)) {
3571
+ return false;
3572
+ }
3573
+ // The use of `Object#toString` avoids issues with the `typeof` operator
3574
+ // in Safari 9 which returns 'object' for typed arrays and other constructors.
3575
+ var tag = baseGetTag(value);
3576
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
3163
3577
  }
3164
- function mapBlock(block, migratedContexts) {
3165
- var _a, _b, _c, _d;
3166
- if (isFieldRef(block)) {
3167
- return {
3168
- ...block,
3169
- _type: fieldReferenceTypeName
3170
- };
3578
+ var isFunction_1 = isFunction$1;
3579
+ var root$1 = _root;
3580
+
3581
+ /** Used to detect overreaching core-js shims. */
3582
+ var coreJsData$1 = root$1['__core-js_shared__'];
3583
+ var _coreJsData = coreJsData$1;
3584
+ var coreJsData = _coreJsData;
3585
+
3586
+ /** Used to detect methods masquerading as native. */
3587
+ var maskSrcKey = function () {
3588
+ var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
3589
+ return uid ? 'Symbol(src)_1.' + uid : '';
3590
+ }();
3591
+
3592
+ /**
3593
+ * Checks if `func` has its source masked.
3594
+ *
3595
+ * @private
3596
+ * @param {Function} func The function to check.
3597
+ * @returns {boolean} Returns `true` if `func` is masked, else `false`.
3598
+ */
3599
+ function isMasked$1(func) {
3600
+ return !!maskSrcKey && maskSrcKey in func;
3601
+ }
3602
+ var _isMasked = isMasked$1;
3603
+
3604
+ /** Used for built-in method references. */
3605
+
3606
+ var funcProto$1 = Function.prototype;
3607
+
3608
+ /** Used to resolve the decompiled source of functions. */
3609
+ var funcToString$1 = funcProto$1.toString;
3610
+
3611
+ /**
3612
+ * Converts `func` to its source code.
3613
+ *
3614
+ * @private
3615
+ * @param {Function} func The function to convert.
3616
+ * @returns {string} Returns the source code.
3617
+ */
3618
+ function toSource$1(func) {
3619
+ if (func != null) {
3620
+ try {
3621
+ return funcToString$1.call(func);
3622
+ } catch (e) {}
3623
+ try {
3624
+ return func + '';
3625
+ } catch (e) {}
3171
3626
  }
3172
- if (isUserInput(block)) {
3173
- return {
3174
- ...block,
3175
- _type: userInputTypeName
3176
- };
3627
+ return '';
3628
+ }
3629
+ var _toSource = toSource$1;
3630
+ var isFunction = isFunction_1,
3631
+ isMasked = _isMasked,
3632
+ isObject = isObject_1,
3633
+ toSource = _toSource;
3634
+
3635
+ /**
3636
+ * Used to match `RegExp`
3637
+ * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
3638
+ */
3639
+ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
3640
+
3641
+ /** Used to detect host constructors (Safari). */
3642
+ var reIsHostCtor = /^\[object .+?Constructor\]$/;
3643
+
3644
+ /** Used for built-in method references. */
3645
+ var funcProto = Function.prototype,
3646
+ objectProto$2 = Object.prototype;
3647
+
3648
+ /** Used to resolve the decompiled source of functions. */
3649
+ var funcToString = funcProto.toString;
3650
+
3651
+ /** Used to check objects for own properties. */
3652
+ var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
3653
+
3654
+ /** Used to detect if a method is native. */
3655
+ var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty$2).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
3656
+
3657
+ /**
3658
+ * The base implementation of `_.isNative` without bad shim checks.
3659
+ *
3660
+ * @private
3661
+ * @param {*} value The value to check.
3662
+ * @returns {boolean} Returns `true` if `value` is a native function,
3663
+ * else `false`.
3664
+ */
3665
+ function baseIsNative$1(value) {
3666
+ if (!isObject(value) || isMasked(value)) {
3667
+ return false;
3177
3668
  }
3178
- if (isContext(block)) {
3179
- const newBlock = {
3180
- ...block,
3181
- _type: instructionContextTypeName,
3182
- reference: {
3183
- _type: "reference",
3184
- _ref: (_c = (_a = migratedContexts.find(c => {
3185
- var _a2;
3186
- return c._alphaId === ((_a2 = block.reference) == null ? void 0 : _a2._ref);
3187
- })) == null ? void 0 : _a._id) != null ? _c : (_b = block.reference) == null ? void 0 : _b._ref
3188
- }
3189
- };
3190
- return newBlock;
3669
+ var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3670
+ return pattern.test(toSource(value));
3671
+ }
3672
+ var _baseIsNative = baseIsNative$1;
3673
+
3674
+ /**
3675
+ * Gets the value at `key` of `object`.
3676
+ *
3677
+ * @private
3678
+ * @param {Object} [object] The object to query.
3679
+ * @param {string} key The key of the property to get.
3680
+ * @returns {*} Returns the property value.
3681
+ */
3682
+
3683
+ function getValue$1(object, key) {
3684
+ return object == null ? undefined : object[key];
3685
+ }
3686
+ var _getValue = getValue$1;
3687
+ var baseIsNative = _baseIsNative,
3688
+ getValue = _getValue;
3689
+
3690
+ /**
3691
+ * Gets the native function at `key` of `object`.
3692
+ *
3693
+ * @private
3694
+ * @param {Object} object The object to query.
3695
+ * @param {string} key The key of the method to get.
3696
+ * @returns {*} Returns the function if it's native, else `undefined`.
3697
+ */
3698
+ function getNative$2(object, key) {
3699
+ var value = getValue(object, key);
3700
+ return baseIsNative(value) ? value : undefined;
3701
+ }
3702
+ var _getNative = getNative$2;
3703
+ var getNative$1 = _getNative;
3704
+
3705
+ /* Built-in method references that are verified to be native. */
3706
+ var nativeCreate$4 = getNative$1(Object, 'create');
3707
+ var _nativeCreate = nativeCreate$4;
3708
+ var nativeCreate$3 = _nativeCreate;
3709
+
3710
+ /**
3711
+ * Removes all key-value entries from the hash.
3712
+ *
3713
+ * @private
3714
+ * @name clear
3715
+ * @memberOf Hash
3716
+ */
3717
+ function hashClear$1() {
3718
+ this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {};
3719
+ this.size = 0;
3720
+ }
3721
+ var _hashClear = hashClear$1;
3722
+
3723
+ /**
3724
+ * Removes `key` and its value from the hash.
3725
+ *
3726
+ * @private
3727
+ * @name delete
3728
+ * @memberOf Hash
3729
+ * @param {Object} hash The hash to modify.
3730
+ * @param {string} key The key of the value to remove.
3731
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
3732
+ */
3733
+
3734
+ function hashDelete$1(key) {
3735
+ var result = this.has(key) && delete this.__data__[key];
3736
+ this.size -= result ? 1 : 0;
3737
+ return result;
3738
+ }
3739
+ var _hashDelete = hashDelete$1;
3740
+ var nativeCreate$2 = _nativeCreate;
3741
+
3742
+ /** Used to stand-in for `undefined` hash values. */
3743
+ var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
3744
+
3745
+ /** Used for built-in method references. */
3746
+ var objectProto$1 = Object.prototype;
3747
+
3748
+ /** Used to check objects for own properties. */
3749
+ var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
3750
+
3751
+ /**
3752
+ * Gets the hash value for `key`.
3753
+ *
3754
+ * @private
3755
+ * @name get
3756
+ * @memberOf Hash
3757
+ * @param {string} key The key of the value to get.
3758
+ * @returns {*} Returns the entry value.
3759
+ */
3760
+ function hashGet$1(key) {
3761
+ var data = this.__data__;
3762
+ if (nativeCreate$2) {
3763
+ var result = data[key];
3764
+ return result === HASH_UNDEFINED$1 ? undefined : result;
3191
3765
  }
3192
- if (isSpan(block)) {
3193
- return block;
3766
+ return hasOwnProperty$1.call(data, key) ? data[key] : undefined;
3767
+ }
3768
+ var _hashGet = hashGet$1;
3769
+ var nativeCreate$1 = _nativeCreate;
3770
+
3771
+ /** Used for built-in method references. */
3772
+ var objectProto = Object.prototype;
3773
+
3774
+ /** Used to check objects for own properties. */
3775
+ var hasOwnProperty = objectProto.hasOwnProperty;
3776
+
3777
+ /**
3778
+ * Checks if a hash value for `key` exists.
3779
+ *
3780
+ * @private
3781
+ * @name has
3782
+ * @memberOf Hash
3783
+ * @param {string} key The key of the entry to check.
3784
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
3785
+ */
3786
+ function hashHas$1(key) {
3787
+ var data = this.__data__;
3788
+ return nativeCreate$1 ? data[key] !== undefined : hasOwnProperty.call(data, key);
3789
+ }
3790
+ var _hashHas = hashHas$1;
3791
+ var nativeCreate = _nativeCreate;
3792
+
3793
+ /** Used to stand-in for `undefined` hash values. */
3794
+ var HASH_UNDEFINED = '__lodash_hash_undefined__';
3795
+
3796
+ /**
3797
+ * Sets the hash `key` to `value`.
3798
+ *
3799
+ * @private
3800
+ * @name set
3801
+ * @memberOf Hash
3802
+ * @param {string} key The key of the value to set.
3803
+ * @param {*} value The value to set.
3804
+ * @returns {Object} Returns the hash instance.
3805
+ */
3806
+ function hashSet$1(key, value) {
3807
+ var data = this.__data__;
3808
+ this.size += this.has(key) ? 0 : 1;
3809
+ data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
3810
+ return this;
3811
+ }
3812
+ var _hashSet = hashSet$1;
3813
+ var hashClear = _hashClear,
3814
+ hashDelete = _hashDelete,
3815
+ hashGet = _hashGet,
3816
+ hashHas = _hashHas,
3817
+ hashSet = _hashSet;
3818
+
3819
+ /**
3820
+ * Creates a hash object.
3821
+ *
3822
+ * @private
3823
+ * @constructor
3824
+ * @param {Array} [entries] The key-value pairs to cache.
3825
+ */
3826
+ function Hash$1(entries) {
3827
+ var index = -1,
3828
+ length = entries == null ? 0 : entries.length;
3829
+ this.clear();
3830
+ while (++index < length) {
3831
+ var entry = entries[index];
3832
+ this.set(entry[0], entry[1]);
3194
3833
  }
3195
- const textBlock = block;
3196
- return {
3197
- ...textBlock,
3198
- children: ((_d = textBlock.children) != null ? _d : []).map(child => mapBlock(child, migratedContexts))
3834
+ }
3835
+
3836
+ // Add methods to `Hash`.
3837
+ Hash$1.prototype.clear = hashClear;
3838
+ Hash$1.prototype['delete'] = hashDelete;
3839
+ Hash$1.prototype.get = hashGet;
3840
+ Hash$1.prototype.has = hashHas;
3841
+ Hash$1.prototype.set = hashSet;
3842
+ var _Hash = Hash$1;
3843
+
3844
+ /**
3845
+ * Removes all key-value entries from the list cache.
3846
+ *
3847
+ * @private
3848
+ * @name clear
3849
+ * @memberOf ListCache
3850
+ */
3851
+
3852
+ function listCacheClear$1() {
3853
+ this.__data__ = [];
3854
+ this.size = 0;
3855
+ }
3856
+ var _listCacheClear = listCacheClear$1;
3857
+
3858
+ /**
3859
+ * Performs a
3860
+ * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
3861
+ * comparison between two values to determine if they are equivalent.
3862
+ *
3863
+ * @static
3864
+ * @memberOf _
3865
+ * @since 4.0.0
3866
+ * @category Lang
3867
+ * @param {*} value The value to compare.
3868
+ * @param {*} other The other value to compare.
3869
+ * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3870
+ * @example
3871
+ *
3872
+ * var object = { 'a': 1 };
3873
+ * var other = { 'a': 1 };
3874
+ *
3875
+ * _.eq(object, object);
3876
+ * // => true
3877
+ *
3878
+ * _.eq(object, other);
3879
+ * // => false
3880
+ *
3881
+ * _.eq('a', 'a');
3882
+ * // => true
3883
+ *
3884
+ * _.eq('a', Object('a'));
3885
+ * // => false
3886
+ *
3887
+ * _.eq(NaN, NaN);
3888
+ * // => true
3889
+ */
3890
+
3891
+ function eq$1(value, other) {
3892
+ return value === other || value !== value && other !== other;
3893
+ }
3894
+ var eq_1 = eq$1;
3895
+ var eq = eq_1;
3896
+
3897
+ /**
3898
+ * Gets the index at which the `key` is found in `array` of key-value pairs.
3899
+ *
3900
+ * @private
3901
+ * @param {Array} array The array to inspect.
3902
+ * @param {*} key The key to search for.
3903
+ * @returns {number} Returns the index of the matched value, else `-1`.
3904
+ */
3905
+ function assocIndexOf$4(array, key) {
3906
+ var length = array.length;
3907
+ while (length--) {
3908
+ if (eq(array[length][0], key)) {
3909
+ return length;
3910
+ }
3911
+ }
3912
+ return -1;
3913
+ }
3914
+ var _assocIndexOf = assocIndexOf$4;
3915
+ var assocIndexOf$3 = _assocIndexOf;
3916
+
3917
+ /** Used for built-in method references. */
3918
+ var arrayProto = Array.prototype;
3919
+
3920
+ /** Built-in value references. */
3921
+ var splice = arrayProto.splice;
3922
+
3923
+ /**
3924
+ * Removes `key` and its value from the list cache.
3925
+ *
3926
+ * @private
3927
+ * @name delete
3928
+ * @memberOf ListCache
3929
+ * @param {string} key The key of the value to remove.
3930
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
3931
+ */
3932
+ function listCacheDelete$1(key) {
3933
+ var data = this.__data__,
3934
+ index = assocIndexOf$3(data, key);
3935
+ if (index < 0) {
3936
+ return false;
3937
+ }
3938
+ var lastIndex = data.length - 1;
3939
+ if (index == lastIndex) {
3940
+ data.pop();
3941
+ } else {
3942
+ splice.call(data, index, 1);
3943
+ }
3944
+ --this.size;
3945
+ return true;
3946
+ }
3947
+ var _listCacheDelete = listCacheDelete$1;
3948
+ var assocIndexOf$2 = _assocIndexOf;
3949
+
3950
+ /**
3951
+ * Gets the list cache value for `key`.
3952
+ *
3953
+ * @private
3954
+ * @name get
3955
+ * @memberOf ListCache
3956
+ * @param {string} key The key of the value to get.
3957
+ * @returns {*} Returns the entry value.
3958
+ */
3959
+ function listCacheGet$1(key) {
3960
+ var data = this.__data__,
3961
+ index = assocIndexOf$2(data, key);
3962
+ return index < 0 ? undefined : data[index][1];
3963
+ }
3964
+ var _listCacheGet = listCacheGet$1;
3965
+ var assocIndexOf$1 = _assocIndexOf;
3966
+
3967
+ /**
3968
+ * Checks if a list cache value for `key` exists.
3969
+ *
3970
+ * @private
3971
+ * @name has
3972
+ * @memberOf ListCache
3973
+ * @param {string} key The key of the entry to check.
3974
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
3975
+ */
3976
+ function listCacheHas$1(key) {
3977
+ return assocIndexOf$1(this.__data__, key) > -1;
3978
+ }
3979
+ var _listCacheHas = listCacheHas$1;
3980
+ var assocIndexOf = _assocIndexOf;
3981
+
3982
+ /**
3983
+ * Sets the list cache `key` to `value`.
3984
+ *
3985
+ * @private
3986
+ * @name set
3987
+ * @memberOf ListCache
3988
+ * @param {string} key The key of the value to set.
3989
+ * @param {*} value The value to set.
3990
+ * @returns {Object} Returns the list cache instance.
3991
+ */
3992
+ function listCacheSet$1(key, value) {
3993
+ var data = this.__data__,
3994
+ index = assocIndexOf(data, key);
3995
+ if (index < 0) {
3996
+ ++this.size;
3997
+ data.push([key, value]);
3998
+ } else {
3999
+ data[index][1] = value;
4000
+ }
4001
+ return this;
4002
+ }
4003
+ var _listCacheSet = listCacheSet$1;
4004
+ var listCacheClear = _listCacheClear,
4005
+ listCacheDelete = _listCacheDelete,
4006
+ listCacheGet = _listCacheGet,
4007
+ listCacheHas = _listCacheHas,
4008
+ listCacheSet = _listCacheSet;
4009
+
4010
+ /**
4011
+ * Creates an list cache object.
4012
+ *
4013
+ * @private
4014
+ * @constructor
4015
+ * @param {Array} [entries] The key-value pairs to cache.
4016
+ */
4017
+ function ListCache$1(entries) {
4018
+ var index = -1,
4019
+ length = entries == null ? 0 : entries.length;
4020
+ this.clear();
4021
+ while (++index < length) {
4022
+ var entry = entries[index];
4023
+ this.set(entry[0], entry[1]);
4024
+ }
4025
+ }
4026
+
4027
+ // Add methods to `ListCache`.
4028
+ ListCache$1.prototype.clear = listCacheClear;
4029
+ ListCache$1.prototype['delete'] = listCacheDelete;
4030
+ ListCache$1.prototype.get = listCacheGet;
4031
+ ListCache$1.prototype.has = listCacheHas;
4032
+ ListCache$1.prototype.set = listCacheSet;
4033
+ var _ListCache = ListCache$1;
4034
+ var getNative = _getNative,
4035
+ root = _root;
4036
+
4037
+ /* Built-in method references that are verified to be native. */
4038
+ var Map$2 = getNative(root, 'Map');
4039
+ var _Map = Map$2;
4040
+ var Hash = _Hash,
4041
+ ListCache = _ListCache,
4042
+ Map$1 = _Map;
4043
+
4044
+ /**
4045
+ * Removes all key-value entries from the map.
4046
+ *
4047
+ * @private
4048
+ * @name clear
4049
+ * @memberOf MapCache
4050
+ */
4051
+ function mapCacheClear$1() {
4052
+ this.size = 0;
4053
+ this.__data__ = {
4054
+ 'hash': new Hash(),
4055
+ 'map': new (Map$1 || ListCache)(),
4056
+ 'string': new Hash()
3199
4057
  };
3200
4058
  }
4059
+ var _mapCacheClear = mapCacheClear$1;
4060
+
4061
+ /**
4062
+ * Checks if `value` is suitable for use as unique object key.
4063
+ *
4064
+ * @private
4065
+ * @param {*} value The value to check.
4066
+ * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
4067
+ */
4068
+
4069
+ function isKeyable$1(value) {
4070
+ var type = typeof value;
4071
+ return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
4072
+ }
4073
+ var _isKeyable = isKeyable$1;
4074
+ var isKeyable = _isKeyable;
4075
+
4076
+ /**
4077
+ * Gets the data for `map`.
4078
+ *
4079
+ * @private
4080
+ * @param {Object} map The map to query.
4081
+ * @param {string} key The reference key.
4082
+ * @returns {*} Returns the map data.
4083
+ */
4084
+ function getMapData$4(map, key) {
4085
+ var data = map.__data__;
4086
+ return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
4087
+ }
4088
+ var _getMapData = getMapData$4;
4089
+ var getMapData$3 = _getMapData;
4090
+
4091
+ /**
4092
+ * Removes `key` and its value from the map.
4093
+ *
4094
+ * @private
4095
+ * @name delete
4096
+ * @memberOf MapCache
4097
+ * @param {string} key The key of the value to remove.
4098
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
4099
+ */
4100
+ function mapCacheDelete$1(key) {
4101
+ var result = getMapData$3(this, key)['delete'](key);
4102
+ this.size -= result ? 1 : 0;
4103
+ return result;
4104
+ }
4105
+ var _mapCacheDelete = mapCacheDelete$1;
4106
+ var getMapData$2 = _getMapData;
4107
+
4108
+ /**
4109
+ * Gets the map value for `key`.
4110
+ *
4111
+ * @private
4112
+ * @name get
4113
+ * @memberOf MapCache
4114
+ * @param {string} key The key of the value to get.
4115
+ * @returns {*} Returns the entry value.
4116
+ */
4117
+ function mapCacheGet$1(key) {
4118
+ return getMapData$2(this, key).get(key);
4119
+ }
4120
+ var _mapCacheGet = mapCacheGet$1;
4121
+ var getMapData$1 = _getMapData;
4122
+
4123
+ /**
4124
+ * Checks if a map value for `key` exists.
4125
+ *
4126
+ * @private
4127
+ * @name has
4128
+ * @memberOf MapCache
4129
+ * @param {string} key The key of the entry to check.
4130
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
4131
+ */
4132
+ function mapCacheHas$1(key) {
4133
+ return getMapData$1(this, key).has(key);
4134
+ }
4135
+ var _mapCacheHas = mapCacheHas$1;
4136
+ var getMapData = _getMapData;
4137
+
4138
+ /**
4139
+ * Sets the map `key` to `value`.
4140
+ *
4141
+ * @private
4142
+ * @name set
4143
+ * @memberOf MapCache
4144
+ * @param {string} key The key of the value to set.
4145
+ * @param {*} value The value to set.
4146
+ * @returns {Object} Returns the map cache instance.
4147
+ */
4148
+ function mapCacheSet$1(key, value) {
4149
+ var data = getMapData(this, key),
4150
+ size = data.size;
4151
+ data.set(key, value);
4152
+ this.size += data.size == size ? 0 : 1;
4153
+ return this;
4154
+ }
4155
+ var _mapCacheSet = mapCacheSet$1;
4156
+ var mapCacheClear = _mapCacheClear,
4157
+ mapCacheDelete = _mapCacheDelete,
4158
+ mapCacheGet = _mapCacheGet,
4159
+ mapCacheHas = _mapCacheHas,
4160
+ mapCacheSet = _mapCacheSet;
4161
+
4162
+ /**
4163
+ * Creates a map cache object to store key-value pairs.
4164
+ *
4165
+ * @private
4166
+ * @constructor
4167
+ * @param {Array} [entries] The key-value pairs to cache.
4168
+ */
4169
+ function MapCache$1(entries) {
4170
+ var index = -1,
4171
+ length = entries == null ? 0 : entries.length;
4172
+ this.clear();
4173
+ while (++index < length) {
4174
+ var entry = entries[index];
4175
+ this.set(entry[0], entry[1]);
4176
+ }
4177
+ }
4178
+
4179
+ // Add methods to `MapCache`.
4180
+ MapCache$1.prototype.clear = mapCacheClear;
4181
+ MapCache$1.prototype['delete'] = mapCacheDelete;
4182
+ MapCache$1.prototype.get = mapCacheGet;
4183
+ MapCache$1.prototype.has = mapCacheHas;
4184
+ MapCache$1.prototype.set = mapCacheSet;
4185
+ var _MapCache = MapCache$1;
4186
+ var MapCache = _MapCache;
4187
+
4188
+ /** Error message constants. */
4189
+ var FUNC_ERROR_TEXT = 'Expected a function';
4190
+
4191
+ /**
4192
+ * Creates a function that memoizes the result of `func`. If `resolver` is
4193
+ * provided, it determines the cache key for storing the result based on the
4194
+ * arguments provided to the memoized function. By default, the first argument
4195
+ * provided to the memoized function is used as the map cache key. The `func`
4196
+ * is invoked with the `this` binding of the memoized function.
4197
+ *
4198
+ * **Note:** The cache is exposed as the `cache` property on the memoized
4199
+ * function. Its creation may be customized by replacing the `_.memoize.Cache`
4200
+ * constructor with one whose instances implement the
4201
+ * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
4202
+ * method interface of `clear`, `delete`, `get`, `has`, and `set`.
4203
+ *
4204
+ * @static
4205
+ * @memberOf _
4206
+ * @since 0.1.0
4207
+ * @category Function
4208
+ * @param {Function} func The function to have its output memoized.
4209
+ * @param {Function} [resolver] The function to resolve the cache key.
4210
+ * @returns {Function} Returns the new memoized function.
4211
+ * @example
4212
+ *
4213
+ * var object = { 'a': 1, 'b': 2 };
4214
+ * var other = { 'c': 3, 'd': 4 };
4215
+ *
4216
+ * var values = _.memoize(_.values);
4217
+ * values(object);
4218
+ * // => [1, 2]
4219
+ *
4220
+ * values(other);
4221
+ * // => [3, 4]
4222
+ *
4223
+ * object.a = 2;
4224
+ * values(object);
4225
+ * // => [1, 2]
4226
+ *
4227
+ * // Modify the result cache.
4228
+ * values.cache.set(object, ['a', 'b']);
4229
+ * values(object);
4230
+ * // => ['a', 'b']
4231
+ *
4232
+ * // Replace `_.memoize.Cache`.
4233
+ * _.memoize.Cache = WeakMap;
4234
+ */
4235
+ function memoize$1(func, resolver) {
4236
+ if (typeof func != 'function' || resolver != null && typeof resolver != 'function') {
4237
+ throw new TypeError(FUNC_ERROR_TEXT);
4238
+ }
4239
+ var memoized = function () {
4240
+ var args = arguments,
4241
+ key = resolver ? resolver.apply(this, args) : args[0],
4242
+ cache = memoized.cache;
4243
+ if (cache.has(key)) {
4244
+ return cache.get(key);
4245
+ }
4246
+ var result = func.apply(this, args);
4247
+ memoized.cache = cache.set(key, result) || cache;
4248
+ return result;
4249
+ };
4250
+ memoized.cache = new (memoize$1.Cache || MapCache)();
4251
+ return memoized;
4252
+ }
4253
+
4254
+ // Expose `MapCache`.
4255
+ memoize$1.Cache = MapCache;
4256
+ var memoize_1 = memoize$1;
4257
+ var memoize = memoize_1;
4258
+
4259
+ /** Used as the maximum memoize cache size. */
4260
+ var MAX_MEMOIZE_SIZE = 500;
4261
+
4262
+ /**
4263
+ * A specialized version of `_.memoize` which clears the memoized function's
4264
+ * cache when it exceeds `MAX_MEMOIZE_SIZE`.
4265
+ *
4266
+ * @private
4267
+ * @param {Function} func The function to have its output memoized.
4268
+ * @returns {Function} Returns the new memoized function.
4269
+ */
4270
+ function memoizeCapped$1(func) {
4271
+ var result = memoize(func, function (key) {
4272
+ if (cache.size === MAX_MEMOIZE_SIZE) {
4273
+ cache.clear();
4274
+ }
4275
+ return key;
4276
+ });
4277
+ var cache = result.cache;
4278
+ return result;
4279
+ }
4280
+ var _memoizeCapped = memoizeCapped$1;
4281
+ var memoizeCapped = _memoizeCapped;
4282
+
4283
+ /** Used to match property names within property paths. */
4284
+ var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
4285
+
4286
+ /** Used to match backslashes in property paths. */
4287
+ var reEscapeChar = /\\(\\)?/g;
4288
+
4289
+ /**
4290
+ * Converts `string` to a property path array.
4291
+ *
4292
+ * @private
4293
+ * @param {string} string The string to convert.
4294
+ * @returns {Array} Returns the property path array.
4295
+ */
4296
+ var stringToPath$1 = memoizeCapped(function (string) {
4297
+ var result = [];
4298
+ if (string.charCodeAt(0) === 46 /* . */) {
4299
+ result.push('');
4300
+ }
4301
+ string.replace(rePropName, function (match, number, quote, subString) {
4302
+ result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
4303
+ });
4304
+ return result;
4305
+ });
4306
+ var _stringToPath = stringToPath$1;
4307
+
4308
+ /**
4309
+ * A specialized version of `_.map` for arrays without support for iteratee
4310
+ * shorthands.
4311
+ *
4312
+ * @private
4313
+ * @param {Array} [array] The array to iterate over.
4314
+ * @param {Function} iteratee The function invoked per iteration.
4315
+ * @returns {Array} Returns the new mapped array.
4316
+ */
4317
+
4318
+ function arrayMap$1(array, iteratee) {
4319
+ var index = -1,
4320
+ length = array == null ? 0 : array.length,
4321
+ result = Array(length);
4322
+ while (++index < length) {
4323
+ result[index] = iteratee(array[index], index, array);
4324
+ }
4325
+ return result;
4326
+ }
4327
+ var _arrayMap = arrayMap$1;
4328
+ var Symbol = _Symbol,
4329
+ arrayMap = _arrayMap,
4330
+ isArray$1 = isArray_1,
4331
+ isSymbol$1 = isSymbol_1;
4332
+
4333
+ /** Used as references for various `Number` constants. */
4334
+ var INFINITY$1 = 1 / 0;
4335
+
4336
+ /** Used to convert symbols to primitives and strings. */
4337
+ var symbolProto = Symbol ? Symbol.prototype : undefined,
4338
+ symbolToString = symbolProto ? symbolProto.toString : undefined;
4339
+
4340
+ /**
4341
+ * The base implementation of `_.toString` which doesn't convert nullish
4342
+ * values to empty strings.
4343
+ *
4344
+ * @private
4345
+ * @param {*} value The value to process.
4346
+ * @returns {string} Returns the string.
4347
+ */
4348
+ function baseToString$1(value) {
4349
+ // Exit early for strings to avoid a performance hit in some environments.
4350
+ if (typeof value == 'string') {
4351
+ return value;
4352
+ }
4353
+ if (isArray$1(value)) {
4354
+ // Recursively convert values (susceptible to call stack limits).
4355
+ return arrayMap(value, baseToString$1) + '';
4356
+ }
4357
+ if (isSymbol$1(value)) {
4358
+ return symbolToString ? symbolToString.call(value) : '';
4359
+ }
4360
+ var result = value + '';
4361
+ return result == '0' && 1 / value == -INFINITY$1 ? '-0' : result;
4362
+ }
4363
+ var _baseToString = baseToString$1;
4364
+ var baseToString = _baseToString;
4365
+
4366
+ /**
4367
+ * Converts `value` to a string. An empty string is returned for `null`
4368
+ * and `undefined` values. The sign of `-0` is preserved.
4369
+ *
4370
+ * @static
4371
+ * @memberOf _
4372
+ * @since 4.0.0
4373
+ * @category Lang
4374
+ * @param {*} value The value to convert.
4375
+ * @returns {string} Returns the converted string.
4376
+ * @example
4377
+ *
4378
+ * _.toString(null);
4379
+ * // => ''
4380
+ *
4381
+ * _.toString(-0);
4382
+ * // => '-0'
4383
+ *
4384
+ * _.toString([1, 2, 3]);
4385
+ * // => '1,2,3'
4386
+ */
4387
+ function toString$1(value) {
4388
+ return value == null ? '' : baseToString(value);
4389
+ }
4390
+ var toString_1 = toString$1;
4391
+ var isArray = isArray_1,
4392
+ isKey = _isKey,
4393
+ stringToPath = _stringToPath,
4394
+ toString = toString_1;
4395
+
4396
+ /**
4397
+ * Casts `value` to a path array if it's not one.
4398
+ *
4399
+ * @private
4400
+ * @param {*} value The value to inspect.
4401
+ * @param {Object} [object] The object to query keys on.
4402
+ * @returns {Array} Returns the cast property path array.
4403
+ */
4404
+ function castPath$1(value, object) {
4405
+ if (isArray(value)) {
4406
+ return value;
4407
+ }
4408
+ return isKey(value, object) ? [value] : stringToPath(toString(value));
4409
+ }
4410
+ var _castPath = castPath$1;
4411
+ var isSymbol = isSymbol_1;
4412
+
4413
+ /** Used as references for various `Number` constants. */
4414
+ var INFINITY = 1 / 0;
4415
+
4416
+ /**
4417
+ * Converts `value` to a string key if it's not a string or symbol.
4418
+ *
4419
+ * @private
4420
+ * @param {*} value The value to inspect.
4421
+ * @returns {string|symbol} Returns the key.
4422
+ */
4423
+ function toKey$1(value) {
4424
+ if (typeof value == 'string' || isSymbol(value)) {
4425
+ return value;
4426
+ }
4427
+ var result = value + '';
4428
+ return result == '0' && 1 / value == -INFINITY ? '-0' : result;
4429
+ }
4430
+ var _toKey = toKey$1;
4431
+ var castPath = _castPath,
4432
+ toKey = _toKey;
4433
+
4434
+ /**
4435
+ * The base implementation of `_.get` without support for default values.
4436
+ *
4437
+ * @private
4438
+ * @param {Object} object The object to query.
4439
+ * @param {Array|string} path The path of the property to get.
4440
+ * @returns {*} Returns the resolved value.
4441
+ */
4442
+ function baseGet$1(object, path) {
4443
+ path = castPath(path, object);
4444
+ var index = 0,
4445
+ length = path.length;
4446
+ while (object != null && index < length) {
4447
+ object = object[toKey(path[index++])];
4448
+ }
4449
+ return index && index == length ? object : undefined;
4450
+ }
4451
+ var _baseGet = baseGet$1;
4452
+ var baseGet = _baseGet;
4453
+
4454
+ /**
4455
+ * Gets the value at `path` of `object`. If the resolved value is
4456
+ * `undefined`, the `defaultValue` is returned in its place.
4457
+ *
4458
+ * @static
4459
+ * @memberOf _
4460
+ * @since 3.7.0
4461
+ * @category Object
4462
+ * @param {Object} object The object to query.
4463
+ * @param {Array|string} path The path of the property to get.
4464
+ * @param {*} [defaultValue] The value returned for `undefined` resolved values.
4465
+ * @returns {*} Returns the resolved value.
4466
+ * @example
4467
+ *
4468
+ * var object = { 'a': [{ 'b': { 'c': 3 } }] };
4469
+ *
4470
+ * _.get(object, 'a[0].b.c');
4471
+ * // => 3
4472
+ *
4473
+ * _.get(object, ['a', '0', 'b', 'c']);
4474
+ * // => 3
4475
+ *
4476
+ * _.get(object, 'a.b.c', 'default');
4477
+ * // => 'default'
4478
+ */
4479
+ function get(object, path, defaultValue) {
4480
+ var result = object == null ? undefined : baseGet(object, path);
4481
+ return result === undefined ? defaultValue : result;
4482
+ }
4483
+ var get_1 = get;
4484
+ var get$1 = /*@__PURE__*/getDefaultExportFromCjs(get_1);
4485
+ const getLanguageParams = (select, document) => {
4486
+ if (!select || !document) {
4487
+ return {};
4488
+ }
4489
+ const selection = select || {};
4490
+ const selectedValue = {};
4491
+ for (const [key, path] of Object.entries(selection)) {
4492
+ let value = get$1(document, path);
4493
+ if (Array.isArray(value)) {
4494
+ value = value.filter(item => typeof item === "object" ? (item == null ? void 0 : item._type) !== "reference" || "_ref" in item : true);
4495
+ }
4496
+ selectedValue[key] = value;
4497
+ }
4498
+ return selectedValue;
4499
+ };
4500
+ const toFieldLanguagesKeyPrefix = "sanityStudio:assist:field-languages:from:";
4501
+ function getPreferredToFieldLanguages(fromLanguageId) {
4502
+ if (typeof localStorage === "undefined") {
4503
+ return [];
4504
+ }
4505
+ const value = localStorage.getItem("".concat(toFieldLanguagesKeyPrefix).concat(fromLanguageId));
4506
+ return value ? JSON.parse(value) : [];
4507
+ }
4508
+ function setPreferredToFieldLanguages(fromLanguageId, languageIds) {
4509
+ if (typeof localStorage === "undefined") {
4510
+ return;
4511
+ }
4512
+ localStorage.setItem("".concat(toFieldLanguagesKeyPrefix).concat(fromLanguageId), JSON.stringify(languageIds));
4513
+ }
4514
+ const FieldTranslationContext = createContext({
4515
+ openFieldTranslation: () => {},
4516
+ translationLoading: false
4517
+ });
4518
+ function useFieldTranslation() {
4519
+ return useContext(FieldTranslationContext);
4520
+ }
4521
+ function hasValuesToTranslate(fieldLanguageMaps, fromLanguage, basePath) {
4522
+ return fieldLanguageMaps == null ? void 0 : fieldLanguageMaps.some(map => map.inputLanguageId === (fromLanguage == null ? void 0 : fromLanguage.id) && map.inputPath && pathToString(map.inputPath).startsWith(pathToString(basePath)));
4523
+ }
4524
+ function FieldTranslationProvider(props) {
4525
+ var _a, _b, _c;
4526
+ const {
4527
+ config: assistConfig
4528
+ } = useAiAssistanceConfig();
4529
+ const apiClient = useApiClient(assistConfig.__customApiClient);
4530
+ const config = (_a = assistConfig.translate) == null ? void 0 : _a.field;
4531
+ const {
4532
+ translate: runTranslate
4533
+ } = useTranslate(apiClient);
4534
+ const [dialogOpen, setDialogOpen] = useState(false);
4535
+ const [fieldTranslationParams, setFieldTranslationParams] = useState();
4536
+ const [languages, setLanguages] = useState();
4537
+ const [fromLanguage, setFromLanguage] = useState(void 0);
4538
+ const [toLanguages, setToLanguages] = useState(void 0);
4539
+ const [fieldLanguageMaps, setFieldLanguageMaps] = useState();
4540
+ const close = useCallback(() => {
4541
+ setDialogOpen(false);
4542
+ setLanguages(void 0);
4543
+ setFieldTranslationParams(void 0);
4544
+ }, []);
4545
+ const languageClient = useClient({
4546
+ apiVersion: (_b = config == null ? void 0 : config.apiVersion) != null ? _b : "2022-11-27"
4547
+ });
4548
+ const documentId = (_c = fieldTranslationParams == null ? void 0 : fieldTranslationParams.document) == null ? void 0 : _c._id;
4549
+ const id = useId();
4550
+ const selectFromLanguage = useCallback((from, languages2, params) => {
4551
+ var _a2, _b2;
4552
+ const {
4553
+ document,
4554
+ documentSchema
4555
+ } = params != null ? params : {};
4556
+ setFromLanguage(from);
4557
+ if (!document || !documentSchema || !params || !languages2) {
4558
+ setFieldLanguageMaps(void 0);
4559
+ return;
4560
+ }
4561
+ const preferred = getPreferredToFieldLanguages(from.id);
4562
+ const allToLanguages = languages2.filter(l => l.id !== (from == null ? void 0 : from.id));
4563
+ const filteredToLanguages = allToLanguages.filter(l => !preferred.length || preferred.includes(l.id));
4564
+ setToLanguages(filteredToLanguages);
4565
+ const fromId = from == null ? void 0 : from.id;
4566
+ const allToIds = (_a2 = allToLanguages == null ? void 0 : allToLanguages.map(l => l.id)) != null ? _a2 : [];
4567
+ const docMembers = getDocumentMembersFlat(document, documentSchema);
4568
+ if (fromId && (allToIds == null ? void 0 : allToIds.length)) {
4569
+ const transMap = getFieldLanguageMap(documentSchema, docMembers, fromId, allToIds.filter(toId => fromId !== toId), (_b2 = config == null ? void 0 : config.translationOutputs) != null ? _b2 : defaultLanguageOutputs);
4570
+ setFieldLanguageMaps(transMap);
4571
+ } else {
4572
+ setFieldLanguageMaps(void 0);
4573
+ }
4574
+ }, [config]);
4575
+ const toggleToLanguage = useCallback((toggledLang, toLanguages2, languages2) => {
4576
+ if (!languages2 || !fromLanguage) {
4577
+ return;
4578
+ }
4579
+ const wasSelected = !!(toLanguages2 == null ? void 0 : toLanguages2.find(l => l.id === toggledLang.id));
4580
+ const newToLangs = languages2.filter(anyLang => !!(toLanguages2 == null ? void 0 : toLanguages2.find(selectedLang => toggledLang.id !== selectedLang.id && selectedLang.id === anyLang.id)) || toggledLang.id === anyLang.id && !wasSelected);
4581
+ setToLanguages(newToLangs);
4582
+ setPreferredToFieldLanguages(fromLanguage.id, newToLangs.map(l => l.id));
4583
+ }, [fromLanguage]);
4584
+ const openFieldTranslation = useCallback(async params => {
4585
+ setDialogOpen(true);
4586
+ const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams, params.document);
4587
+ const languages2 = await (typeof (config == null ? void 0 : config.languages) === "function" ? config == null ? void 0 : config.languages(languageClient, languageParams) : Promise.resolve(config == null ? void 0 : config.languages));
4588
+ setLanguages(languages2);
4589
+ setFieldTranslationParams(params);
4590
+ const fromLanguage2 = languages2 == null ? void 0 : languages2[0];
4591
+ if (fromLanguage2) {
4592
+ selectFromLanguage(fromLanguage2, languages2, params);
4593
+ } else {
4594
+ console.error("No languages available for selected language params", languageParams);
4595
+ }
4596
+ }, [selectFromLanguage, config, languageClient]);
4597
+ const contextValue = useMemo(() => {
4598
+ return {
4599
+ openFieldTranslation,
4600
+ translationLoading: false
4601
+ };
4602
+ }, [openFieldTranslation]);
4603
+ const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(fieldLanguageMaps == null ? void 0 : fieldLanguageMaps.length) || !documentId || !hasValuesToTranslate(fieldLanguageMaps, fromLanguage, fieldTranslationParams.translatePath);
4604
+ const onRunTranslation = useCallback(() => {
4605
+ const translatePath = fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath;
4606
+ if (fieldLanguageMaps && documentId && translatePath) {
4607
+ runTranslate({
4608
+ documentId,
4609
+ translatePath,
4610
+ fieldLanguageMap: fieldLanguageMaps.map(map => ({
4611
+ ...map,
4612
+ // eslint-disable-next-line max-nested-callbacks
4613
+ outputs: map.outputs.filter(out => !!(toLanguages == null ? void 0 : toLanguages.find(l => l.id === out.id)))
4614
+ })),
4615
+ conditionalMembers: fieldTranslationParams == null ? void 0 : fieldTranslationParams.conditionalMembers
4616
+ });
4617
+ }
4618
+ close();
4619
+ }, [fieldLanguageMaps, documentId, runTranslate, close, toLanguages, fieldTranslationParams == null ? void 0 : fieldTranslationParams.translatePath]);
4620
+ const runButton = /* @__PURE__ */jsx(Button, {
4621
+ text: "Translate",
4622
+ tone: "primary",
4623
+ icon: PlayIcon,
4624
+ style: {
4625
+ width: "100%"
4626
+ },
4627
+ disabled: runDisabled,
4628
+ onClick: onRunTranslation
4629
+ });
4630
+ return /* @__PURE__ */jsxs(FieldTranslationContext.Provider, {
4631
+ value: contextValue,
4632
+ children: [dialogOpen ? /* @__PURE__ */jsx(Dialog, {
4633
+ id,
4634
+ width: 1,
4635
+ open: dialogOpen,
4636
+ onClose: close,
4637
+ header: "Translate fields",
4638
+ footer: /* @__PURE__ */jsx(Flex, {
4639
+ justify: "space-between",
4640
+ padding: 2,
4641
+ flex: 1,
4642
+ children: runDisabled ? /* @__PURE__ */jsx(Tooltip, {
4643
+ content: /* @__PURE__ */jsx(Flex, {
4644
+ padding: 2,
4645
+ children: /* @__PURE__ */jsx(Text, {
4646
+ children: "There is nothing to translate in the selected from-language."
4647
+ })
4648
+ }),
4649
+ placement: "top",
4650
+ children: /* @__PURE__ */jsx(Flex, {
4651
+ flex: 1,
4652
+ children: runButton
4653
+ })
4654
+ }) : runButton
4655
+ }),
4656
+ children: languages ? /* @__PURE__ */jsxs(Flex, {
4657
+ padding: 4,
4658
+ gap: 5,
4659
+ align: "flex-start",
4660
+ justify: "center",
4661
+ children: [/* @__PURE__ */jsxs(Stack, {
4662
+ space: 2,
4663
+ children: [/* @__PURE__ */jsx(Box, {
4664
+ marginBottom: 2,
4665
+ children: /* @__PURE__ */jsx(Text, {
4666
+ weight: "semibold",
4667
+ children: "From"
4668
+ })
4669
+ }), languages == null ? void 0 : languages.map(l => {
4670
+ var _a2;
4671
+ return /* @__PURE__ */jsxs(Flex, {
4672
+ gap: 3,
4673
+ align: "center",
4674
+ as: "label",
4675
+ children: [/* @__PURE__ */jsx(Radio, {
4676
+ name: "fromLang",
4677
+ value: l.id,
4678
+ checked: l.id === (fromLanguage == null ? void 0 : fromLanguage.id),
4679
+ onChange: () => selectFromLanguage(l, languages, fieldTranslationParams)
4680
+ }), /* @__PURE__ */jsx(Text, {
4681
+ children: (_a2 = l.title) != null ? _a2 : l.id
4682
+ })]
4683
+ }, l.id);
4684
+ })]
4685
+ }), /* @__PURE__ */jsxs(Stack, {
4686
+ space: 2,
4687
+ children: [/* @__PURE__ */jsx(Box, {
4688
+ marginBottom: 2,
4689
+ children: /* @__PURE__ */jsx(Text, {
4690
+ weight: "semibold",
4691
+ children: "To"
4692
+ })
4693
+ }), languages.map(l => {
4694
+ var _a2;
4695
+ return /* @__PURE__ */jsxs(Flex, {
4696
+ gap: 3,
4697
+ align: "center",
4698
+ as: "label",
4699
+ style: l.id === (fromLanguage == null ? void 0 : fromLanguage.id) ? {
4700
+ opacity: 0.5
4701
+ } : void 0,
4702
+ children: [/* @__PURE__ */jsx(Checkbox, {
4703
+ name: "toLang",
4704
+ value: l.id,
4705
+ checked: l.id !== (fromLanguage == null ? void 0 : fromLanguage.id) && !!(toLanguages == null ? void 0 : toLanguages.find(tl => tl.id === l.id)),
4706
+ onChange: () => toggleToLanguage(l, toLanguages, languages),
4707
+ disabled: l.id === (fromLanguage == null ? void 0 : fromLanguage.id)
4708
+ }), /* @__PURE__ */jsx(Text, {
4709
+ muted: l.id === (fromLanguage == null ? void 0 : fromLanguage.id),
4710
+ children: (_a2 = l.title) != null ? _a2 : l.id
4711
+ })]
4712
+ }, l.id);
4713
+ })]
4714
+ })]
4715
+ }) : /* @__PURE__ */jsxs(Flex, {
4716
+ padding: 4,
4717
+ gap: 2,
4718
+ align: "flex-start",
4719
+ justify: "center",
4720
+ children: [/* @__PURE__ */jsx(Box, {
4721
+ children: /* @__PURE__ */jsx(Spinner, {})
4722
+ }), /* @__PURE__ */jsx(Text, {
4723
+ children: "Loading languages..."
4724
+ })]
4725
+ })
4726
+ }) : null, props.children]
4727
+ });
4728
+ }
3201
4729
  function AssistLayout(props) {
3202
- var _a;
3203
4730
  const [connectors, setConnectors] = useState([]);
3204
- const migrate = (_a = props.config.alphaMigration) != null ? _a : true;
3205
- return /* @__PURE__ */jsxs(AiAssistanceConfigProvider, {
4731
+ return /* @__PURE__ */jsx(AiAssistanceConfigProvider, {
3206
4732
  config: props.config,
3207
- children: [migrate ? /* @__PURE__ */jsx(AlphaMigration, {}) : null, /* @__PURE__ */jsx(RunInstructionProvider, {
3208
- children: /* @__PURE__ */jsxs(ConnectorsProvider, {
3209
- onConnectorsChange: setConnectors,
3210
- children: [props.renderDefault(props), /* @__PURE__ */jsx(ThemeProvider, {
3211
- tone: "default",
3212
- children: /* @__PURE__ */jsx(AssistConnectorsOverlay, {
3213
- connectors
3214
- })
3215
- })]
4733
+ children: /* @__PURE__ */jsx(RunInstructionProvider, {
4734
+ children: /* @__PURE__ */jsx(FieldTranslationProvider, {
4735
+ children: /* @__PURE__ */jsxs(ConnectorsProvider, {
4736
+ onConnectorsChange: setConnectors,
4737
+ children: [props.renderDefault(props), /* @__PURE__ */jsx(ThemeProvider, {
4738
+ tone: "default",
4739
+ children: /* @__PURE__ */jsx(AssistConnectorsOverlay, {
4740
+ connectors
4741
+ })
4742
+ })]
4743
+ })
3216
4744
  })
3217
- })]
4745
+ })
3218
4746
  });
3219
4747
  }
3220
4748
  var __freeze$1 = Object.freeze;
@@ -3240,7 +4768,10 @@ function ErrorWrapper(props) {
3240
4768
  const catchError = useCallback(params => {
3241
4769
  setError(params.error);
3242
4770
  }, [setError]);
3243
- const unsetValue = useCallback(() => onChange(PatchEvent.from(unset())), [onChange]);
4771
+ const unsetValue = useCallback(() => {
4772
+ onChange(PatchEvent.from(unset()));
4773
+ setError(void 0);
4774
+ }, [onChange]);
3244
4775
  const dismiss = useCallback(() => setError(void 0), []);
3245
4776
  const catcher = /* @__PURE__ */jsx(ErrorBoundary, {
3246
4777
  onCatch: catchError,
@@ -3308,6 +4839,7 @@ function AssistFormBlock(props) {
3308
4839
  _key: key
3309
4840
  }));
3310
4841
  }, [onChange, key]);
4842
+ const singlePresence = presence[0];
3311
4843
  return /* @__PURE__ */jsx(ErrorWrapper, {
3312
4844
  onChange: localOnChange,
3313
4845
  children: /* @__PURE__ */jsxs(Flex, {
@@ -3316,9 +4848,9 @@ function AssistFormBlock(props) {
3316
4848
  children: [/* @__PURE__ */jsx(Box, {
3317
4849
  flex: 1,
3318
4850
  children: props.renderDefault(props)
3319
- }), presence.map(pre => /* @__PURE__ */jsx(AiFieldPresence, {
3320
- presence: pre
3321
- }, pre.lastActiveAt))]
4851
+ }), singlePresence && /* @__PURE__ */jsx(AiFieldPresence, {
4852
+ presence: singlePresence
4853
+ })]
3322
4854
  })
3323
4855
  });
3324
4856
  }
@@ -3362,16 +4894,24 @@ function InstructionInput(props) {
3362
4894
  ...props
3363
4895
  }), /* @__PURE__ */jsx(ShareField, {
3364
4896
  ...props
3365
- }), /* @__PURE__ */jsx(PromptField, {
4897
+ }), /* @__PURE__ */jsx(ObjectMember, {
4898
+ fieldName: "prompt",
4899
+ ...props
4900
+ }), /* @__PURE__ */jsx(ObjectMember, {
4901
+ fieldName: "output",
3366
4902
  ...props
3367
4903
  })]
3368
4904
  });
3369
4905
  }
3370
- function PromptField(props) {
3371
- const promptMember = findFieldMember(props.members, "prompt");
3372
- return promptMember ? /* @__PURE__ */jsx(ObjectInputMember, {
4906
+ function ObjectMember(_ref13) {
4907
+ let {
4908
+ fieldName,
4909
+ ...props
4910
+ } = _ref13;
4911
+ const member = findFieldMember(props.members, fieldName);
4912
+ return member ? /* @__PURE__ */jsx(ObjectInputMember, {
3373
4913
  ...props,
3374
- member: promptMember
4914
+ member
3375
4915
  }) : null;
3376
4916
  }
3377
4917
  const NONE = [];
@@ -3506,8 +5046,8 @@ function IconInput(props) {
3506
5046
  onChange
3507
5047
  } = props;
3508
5048
  const id = useId();
3509
- const items = useMemo(() => Object.entries(icons).map(_ref10 => {
3510
- let [key, icon] = _ref10;
5049
+ const items = useMemo(() => Object.entries(icons).map(_ref14 => {
5050
+ let [key, icon] = _ref14;
3511
5051
  return /* @__PURE__ */jsx(IconItem, {
3512
5052
  iconKey: key,
3513
5053
  icon,
@@ -3535,12 +5075,12 @@ function IconInput(props) {
3535
5075
  }
3536
5076
  });
3537
5077
  }
3538
- function IconItem(_ref11) {
5078
+ function IconItem(_ref15) {
3539
5079
  let {
3540
5080
  icon,
3541
5081
  iconKey: key,
3542
5082
  onChange
3543
- } = _ref11;
5083
+ } = _ref15;
3544
5084
  const onClick = useCallback(() => onChange(set(key)), [onChange, key]);
3545
5085
  return /* @__PURE__ */jsx(MenuItem, {
3546
5086
  icon,
@@ -3551,8 +5091,8 @@ function IconItem(_ref11) {
3551
5091
  }
3552
5092
  function getIcon(iconName) {
3553
5093
  var _a, _b;
3554
- return (_b = (_a = Object.entries(icons).find(_ref12 => {
3555
- let [key] = _ref12;
5094
+ return (_b = (_a = Object.entries(icons).find(_ref16 => {
5095
+ let [key] = _ref16;
3556
5096
  return key === iconName;
3557
5097
  })) == null ? void 0 : _a[1]) != null ? _b : icons.sparkles;
3558
5098
  }
@@ -3711,11 +5251,11 @@ const contextDocumentSchema = defineType({
3711
5251
  title: "title",
3712
5252
  context: "context"
3713
5253
  },
3714
- prepare(_ref13) {
5254
+ prepare(_ref17) {
3715
5255
  let {
3716
5256
  title,
3717
5257
  context
3718
- } = _ref13;
5258
+ } = _ref17;
3719
5259
  var _a;
3720
5260
  const text = context == null ? void 0 : context.flatMap(block => block == null ? void 0 : block.children).flatMap(child => {
3721
5261
  var _a2;
@@ -3801,10 +5341,204 @@ function InstructionsArrayField(props) {
3801
5341
  title: " "
3802
5342
  });
3803
5343
  }
5344
+ function InstructionOutputField(props) {
5345
+ var _a;
5346
+ const {
5347
+ fieldSchema
5348
+ } = (_a = useContext(SelectedFieldContext)) != null ? _a : {};
5349
+ if (!fieldSchema || !(isObjectSchemaType(fieldSchema) || isArrayOfObjectsSchemaType(fieldSchema))) {
5350
+ return null;
5351
+ }
5352
+ return /* @__PURE__ */jsx(EnabledOutputField, {
5353
+ ...props,
5354
+ fieldSchema,
5355
+ children: props.children
5356
+ });
5357
+ }
5358
+ function EnabledOutputField(_ref18) {
5359
+ let {
5360
+ fieldSchema,
5361
+ ...props
5362
+ } = _ref18;
5363
+ var _a;
5364
+ const [open, setOpen] = useState(!!((_a = props.value) == null ? void 0 : _a.length));
5365
+ const onExpand = useCallback(() => setOpen(true), []);
5366
+ const onCollapse = useCallback(() => setOpen(false), []);
5367
+ return props.renderDefault({
5368
+ ...props,
5369
+ collapsible: true,
5370
+ onExpand,
5371
+ onCollapse,
5372
+ collapsed: !open,
5373
+ level: 1,
5374
+ title: isObjectSchemaType(fieldSchema) ? "Allowed fields" : "Allowed types"
5375
+ });
5376
+ }
5377
+ function InstructionOutputInput(props) {
5378
+ var _a;
5379
+ const {
5380
+ fieldSchema
5381
+ } = (_a = useContext(SelectedFieldContext)) != null ? _a : {};
5382
+ if (!fieldSchema) {
5383
+ return null;
5384
+ }
5385
+ if (isObjectSchemaType(fieldSchema)) {
5386
+ return /* @__PURE__ */jsx(ObjectOutputInput, {
5387
+ ...props,
5388
+ fieldSchema
5389
+ });
5390
+ }
5391
+ if (isArrayOfObjectsSchemaType(fieldSchema)) {
5392
+ return /* @__PURE__ */jsx(ArrayOutputInput, {
5393
+ ...props,
5394
+ fieldSchema
5395
+ });
5396
+ }
5397
+ return null;
5398
+ }
5399
+ function useEmptySelectAllValue(value, allowedValues, onChange) {
5400
+ useEffect(() => {
5401
+ var _a, _b;
5402
+ const validValues = value == null ? void 0 : value.filter(v => allowedValues.find(f => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type)));
5403
+ const valueLength = (_a = value == null ? void 0 : value.length) != null ? _a : 0;
5404
+ const validLength = (_b = validValues == null ? void 0 : validValues.length) != null ? _b : 0;
5405
+ if (!validLength && valueLength || validLength >= allowedValues.length) {
5406
+ onChange(PatchEvent.from([unset()]));
5407
+ }
5408
+ }, [allowedValues, value, onChange]);
5409
+ }
5410
+ function ObjectOutputInput(_ref19) {
5411
+ let {
5412
+ fieldSchema,
5413
+ ...props
5414
+ } = _ref19;
5415
+ const {
5416
+ value,
5417
+ onChange
5418
+ } = props;
5419
+ const fields = useMemo(() => fieldSchema.fields.filter(field => isAssistSupported(field.type)), [fieldSchema.fields]);
5420
+ useEmptySelectAllValue(value, fields, onChange);
5421
+ const onSelectChange = useCallback((checked, selectedValue) => {
5422
+ if (checked) {
5423
+ if (value == null ? void 0 : value.length) {
5424
+ onChange(PatchEvent.from(unset([{
5425
+ _key: selectedValue
5426
+ }])));
5427
+ } else {
5428
+ const items = fields.filter(f => f.name !== selectedValue).map(field => typed({
5429
+ _key: field.name,
5430
+ _type: "sanity.assist.output.field",
5431
+ relativePath: field.name
5432
+ }));
5433
+ onChange(PatchEvent.from([setIfMissing([]), insert(items, "after", [-1])]));
5434
+ }
5435
+ } else {
5436
+ const patchValue = {
5437
+ _key: selectedValue,
5438
+ _type: "sanity.assist.output.field",
5439
+ relativePath: selectedValue
5440
+ };
5441
+ onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], "after", [-1])]));
5442
+ }
5443
+ }, [onChange, value, fields]);
5444
+ return /* @__PURE__ */jsx(Stack, {
5445
+ space: 2,
5446
+ children: fields.map(field => {
5447
+ var _a;
5448
+ return /* @__PURE__ */jsx(Flex, {
5449
+ align: "center",
5450
+ gap: 2,
5451
+ children: /* @__PURE__ */jsx(Selectable, {
5452
+ value: field.name,
5453
+ title: (_a = field.type.title) != null ? _a : field.name,
5454
+ arrayValue: value,
5455
+ onChange: onSelectChange
5456
+ })
5457
+ }, field.name);
5458
+ })
5459
+ });
5460
+ }
5461
+ function ArrayOutputInput(_ref20) {
5462
+ let {
5463
+ fieldSchema,
5464
+ ...props
5465
+ } = _ref20;
5466
+ const {
5467
+ value,
5468
+ onChange
5469
+ } = props;
5470
+ const ofItems = useMemo(() => fieldSchema.of.filter(itemType => isAssistSupported(itemType)), [fieldSchema.of]);
5471
+ useEmptySelectAllValue(value, ofItems, onChange);
5472
+ const onSelectChange = useCallback((checked, selectedValue) => {
5473
+ if (checked) {
5474
+ if (value == null ? void 0 : value.length) {
5475
+ onChange(PatchEvent.from(unset([{
5476
+ _key: selectedValue
5477
+ }])));
5478
+ } else {
5479
+ const items = ofItems.filter(f => f.name !== selectedValue).map(field => typed({
5480
+ _key: field.name,
5481
+ _type: "sanity.assist.output.type",
5482
+ type: field.name
5483
+ }));
5484
+ onChange(PatchEvent.from([setIfMissing([]), insert(items, "after", [-1])]));
5485
+ }
5486
+ } else {
5487
+ const patchValue = {
5488
+ _key: selectedValue,
5489
+ _type: "sanity.assist.output.type",
5490
+ type: selectedValue
5491
+ };
5492
+ onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], "after", [-1])]));
5493
+ }
5494
+ }, [onChange, value, ofItems]);
5495
+ return /* @__PURE__ */jsx(Stack, {
5496
+ space: 2,
5497
+ children: ofItems.map(itemType => {
5498
+ var _a;
5499
+ return /* @__PURE__ */jsx(Flex, {
5500
+ children: /* @__PURE__ */jsx(Selectable, {
5501
+ value: itemType.name,
5502
+ title: isType(itemType, "block") ? "Text" : (_a = itemType.title) != null ? _a : itemType.name,
5503
+ arrayValue: value,
5504
+ onChange: onSelectChange
5505
+ })
5506
+ }, itemType.name);
5507
+ })
5508
+ });
5509
+ }
5510
+ function Selectable(_ref21) {
5511
+ let {
5512
+ title,
5513
+ arrayValue,
5514
+ value,
5515
+ onChange
5516
+ } = _ref21;
5517
+ const checked = !(arrayValue == null ? void 0 : arrayValue.length) || !!(arrayValue == null ? void 0 : arrayValue.find(v => v._key === value));
5518
+ const handleChange = useCallback(() => onChange(checked, value), [onChange, checked, value]);
5519
+ return /* @__PURE__ */jsxs(Flex, {
5520
+ gap: 2,
5521
+ align: "flex-start",
5522
+ children: [/* @__PURE__ */jsx(Checkbox, {
5523
+ checked,
5524
+ onChange: handleChange
5525
+ }), /* @__PURE__ */jsx(Card, {
5526
+ marginTop: 1,
5527
+ onClick: () => handleChange,
5528
+ children: /* @__PURE__ */jsx(Text, {
5529
+ style: {
5530
+ cursor: "default"
5531
+ },
5532
+ size: 1,
5533
+ children: title
5534
+ })
5535
+ })]
5536
+ });
5537
+ }
3804
5538
  const fieldReference = defineType({
3805
5539
  type: "object",
3806
5540
  name: fieldReferenceTypeName,
3807
- title: "Document field",
5541
+ title: "Field",
3808
5542
  icon: ThListIcon,
3809
5543
  fields: [defineField({
3810
5544
  type: "string",
@@ -3844,10 +5578,10 @@ const fieldReference = defineType({
3844
5578
  select: {
3845
5579
  path: "path"
3846
5580
  },
3847
- prepare(_ref14) {
5581
+ prepare(_ref22) {
3848
5582
  let {
3849
5583
  path
3850
- } = _ref14;
5584
+ } = _ref22;
3851
5585
  return {
3852
5586
  title: path,
3853
5587
  path,
@@ -3974,7 +5708,6 @@ const prompt = defineType({
3974
5708
  type: userInput.name,
3975
5709
  }),*/]
3976
5710
  });
3977
-
3978
5711
  const instruction = defineType({
3979
5712
  type: "object",
3980
5713
  name: instructionTypeName,
@@ -3993,12 +5726,12 @@ const instruction = defineType({
3993
5726
  title: "title",
3994
5727
  userId: "userId"
3995
5728
  },
3996
- prepare: _ref15 => {
5729
+ prepare: _ref23 => {
3997
5730
  let {
3998
5731
  icon,
3999
5732
  title,
4000
5733
  userId
4001
- } = _ref15;
5734
+ } = _ref23;
4002
5735
  return {
4003
5736
  title,
4004
5737
  icon: icon ? icons[icon] : SparklesIcon,
@@ -4103,6 +5836,33 @@ const instruction = defineType({
4103
5836
  var _a, _b;
4104
5837
  return (_b = (_a = context.currentUser) == null ? void 0 : _a.id) != null ? _b : "";
4105
5838
  }
5839
+ }), defineField({
5840
+ type: "array",
5841
+ name: "output",
5842
+ title: "Output filter",
5843
+ components: {
5844
+ input: InstructionOutputInput,
5845
+ field: InstructionOutputField
5846
+ },
5847
+ of: [defineArrayMember({
5848
+ type: "object",
5849
+ name: outputFieldTypeName,
5850
+ title: "Output field",
5851
+ fields: [{
5852
+ type: "string",
5853
+ name: "path",
5854
+ title: "Path"
5855
+ }]
5856
+ }), defineArrayMember({
5857
+ type: "object",
5858
+ name: outputTypeTypeName,
5859
+ title: "Output type",
5860
+ fields: [{
5861
+ type: "string",
5862
+ name: "type",
5863
+ title: "Type"
5864
+ }]
5865
+ })]
4106
5866
  })]
4107
5867
  });
4108
5868
  const fieldInstructions = defineType({
@@ -4319,7 +6079,7 @@ function PrivateIcon() {
4319
6079
  children: /* @__PURE__ */jsx(LockIcon, {})
4320
6080
  });
4321
6081
  }
4322
- const ImageContext = createContext(void 0);
6082
+ const ImageContext = createContext({});
4323
6083
  function ImageContextProvider(props) {
4324
6084
  var _a;
4325
6085
  const {
@@ -4344,28 +6104,30 @@ function ImageContextProvider(props) {
4344
6104
  isSyncing
4345
6105
  } = useSyncState(publicId(documentId), documentSchemaType.name);
4346
6106
  useEffect(() => {
4347
- const captionField = getCaptionFieldOption(schemaType);
4348
- if (assetRef && documentId && captionField && assetRef !== assetRefState && !isSyncing) {
6107
+ const descriptionField = getDescriptionFieldOption(schemaType);
6108
+ if (assetRef && documentId && descriptionField && assetRef !== assetRefState && !isSyncing) {
4349
6109
  setAssetRefState(assetRef);
4350
6110
  generateCaption({
4351
- path: pathToString([...path, captionField]),
6111
+ path: pathToString([...path, descriptionField]),
4352
6112
  documentId
4353
6113
  });
4354
6114
  }
4355
6115
  }, [schemaType, path, assetRef, assetRefState, documentId, generateCaption, isSyncing]);
4356
6116
  const context = useMemo(() => {
4357
- const captionField = getCaptionFieldOption(schemaType);
4358
- return captionField ? {
4359
- captionPath: pathToString([...path, captionField]),
6117
+ const descriptionField = getDescriptionFieldOption(schemaType);
6118
+ const imageInstructionField = getImageInstructionFieldOption(schemaType);
6119
+ return {
6120
+ imageDescriptionPath: descriptionField ? pathToString([...path, descriptionField]) : void 0,
6121
+ imageInstructionPath: imageInstructionField ? pathToString([...path, imageInstructionField]) : void 0,
4360
6122
  assetRef
4361
- } : void 0;
6123
+ };
4362
6124
  }, [schemaType, path, assetRef]);
4363
6125
  return /* @__PURE__ */jsx(ImageContext.Provider, {
4364
6126
  value: context,
4365
6127
  children: props.renderDefault(props)
4366
6128
  });
4367
6129
  }
4368
- function node$1(node2) {
6130
+ function node$3(node2) {
4369
6131
  return node2;
4370
6132
  }
4371
6133
  const generateCaptionsActions = {
@@ -4381,12 +6143,12 @@ const generateCaptionsActions = {
4381
6143
  loading
4382
6144
  } = useGenerateCaption(apiClient);
4383
6145
  const imageContext = useContext(ImageContext);
4384
- if (imageContext && pathKey === (imageContext == null ? void 0 : imageContext.captionPath)) {
6146
+ if (imageContext && pathKey === (imageContext == null ? void 0 : imageContext.imageDescriptionPath)) {
4385
6147
  const {
4386
6148
  documentId
4387
6149
  } = useAssistDocumentContext();
4388
6150
  return useMemo(() => {
4389
- return node$1({
6151
+ return node$3({
4390
6152
  type: "action",
4391
6153
  icon: loading ? () => /* @__PURE__ */jsx(Box, {
4392
6154
  style: {
@@ -4398,7 +6160,7 @@ const generateCaptionsActions = {
4398
6160
  }
4399
6161
  })
4400
6162
  }) : ImageIcon,
4401
- title: "Generate caption",
6163
+ title: "Generate image description",
4402
6164
  onAction: () => {
4403
6165
  if (loading) {
4404
6166
  return;
@@ -4417,6 +6179,182 @@ const generateCaptionsActions = {
4417
6179
  return void 0;
4418
6180
  }
4419
6181
  };
6182
+ function node$2(node2) {
6183
+ return node2;
6184
+ }
6185
+ const translateActions = {
6186
+ name: "sanity-assist-translate",
6187
+ useAction(props) {
6188
+ var _a, _b, _c, _d, _e, _f, _g, _h;
6189
+ const {
6190
+ config,
6191
+ status
6192
+ } = useAiAssistanceConfig();
6193
+ const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
6194
+ const {
6195
+ schemaType: fieldSchemaType,
6196
+ path,
6197
+ documentId,
6198
+ documentSchemaType,
6199
+ documentIsAssistable
6200
+ } = props;
6201
+ const isDocumentLevel = path.length === 0;
6202
+ const readOnly = fieldSchemaType.readOnly === true;
6203
+ const docTransTypes = (_b = (_a = config.translate) == null ? void 0 : _a.document) == null ? void 0 : _b.documentTypes;
6204
+ const options = fieldSchemaType == null ? void 0 : fieldSchemaType.options;
6205
+ const addFieldAction = isDocumentLevel || ((_c = options == null ? void 0 : options.aiAssist) == null ? void 0 : _c.translateAction);
6206
+ const fieldTransEnabled = addFieldAction && (status == null ? void 0 : status.initialized) && documentSchemaType && ((_f = (_e = (_d = config.translate) == null ? void 0 : _d.field) == null ? void 0 : _e.documentTypes) == null ? void 0 : _f.includes(documentSchemaType.name));
6207
+ const documentTranslationEnabled = addFieldAction && (status == null ? void 0 : status.initialized) && documentSchemaType && (!docTransTypes && isAssistSupported(fieldSchemaType) || (docTransTypes == null ? void 0 : docTransTypes.includes(documentSchemaType.name)));
6208
+ if (documentSchemaType && (documentTranslationEnabled || fieldTransEnabled)) {
6209
+ const {
6210
+ value: documentValue,
6211
+ onChange: documentOnChange,
6212
+ formState
6213
+ } = useDocumentPane();
6214
+ const docRef = useRef(documentValue);
6215
+ docRef.current = documentValue;
6216
+ const formStateRef = useRef(formState);
6217
+ formStateRef.current = formState;
6218
+ const translationApi = useTranslate(apiClient);
6219
+ const translate = useDraftDelayedTask({
6220
+ documentOnChange,
6221
+ isDocAssistable: documentIsAssistable != null ? documentIsAssistable : false,
6222
+ task: translationApi.translate
6223
+ });
6224
+ const languagePath = (_h = (_g = config.translate) == null ? void 0 : _g.document) == null ? void 0 : _h.languageField;
6225
+ const translateDocumentAction = useMemo(() => {
6226
+ if (!languagePath || !documentTranslationEnabled) {
6227
+ return void 0;
6228
+ }
6229
+ const title = path.length ? "Translate" : "Translate document";
6230
+ return node$2({
6231
+ type: "action",
6232
+ icon: translationApi.loading ? () => /* @__PURE__ */jsx(Box, {
6233
+ style: {
6234
+ height: 17
6235
+ },
6236
+ children: /* @__PURE__ */jsx(Spinner, {
6237
+ style: {
6238
+ transform: "translateY(6px)"
6239
+ }
6240
+ })
6241
+ }) : TranslateIcon,
6242
+ title,
6243
+ onAction: () => {
6244
+ if (translationApi.loading || !languagePath || !documentId) {
6245
+ return;
6246
+ }
6247
+ translate({
6248
+ languagePath,
6249
+ translatePath: path,
6250
+ documentId: documentId != null ? documentId : "",
6251
+ conditionalMembers: formStateRef.current ? getConditionalMembers(formStateRef.current) : []
6252
+ });
6253
+ },
6254
+ renderAsButton: true,
6255
+ disabled: translationApi.loading || readOnly
6256
+ });
6257
+ }, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled, path, readOnly]);
6258
+ const fieldTranslate = useFieldTranslation();
6259
+ const openFieldTranslation = useDraftDelayedTask({
6260
+ documentOnChange,
6261
+ isDocAssistable: documentIsAssistable != null ? documentIsAssistable : false,
6262
+ task: fieldTranslate.openFieldTranslation
6263
+ });
6264
+ const translateFieldsAction = useMemo(() => fieldTransEnabled ? node$2({
6265
+ type: "action",
6266
+ icon: fieldTranslate.translationLoading ? () => /* @__PURE__ */jsx(Box, {
6267
+ style: {
6268
+ height: 17
6269
+ },
6270
+ children: /* @__PURE__ */jsx(Spinner, {
6271
+ style: {
6272
+ transform: "translateY(6px)"
6273
+ }
6274
+ })
6275
+ }) : TranslateIcon,
6276
+ title: "Translate fields...",
6277
+ onAction: () => {
6278
+ if (fieldTranslate.translationLoading || !documentId) {
6279
+ return;
6280
+ }
6281
+ if (formStateRef.current) {
6282
+ getConditionalMembers(formStateRef.current);
6283
+ }
6284
+ openFieldTranslation({
6285
+ document: docRef.current,
6286
+ documentSchema: documentSchemaType,
6287
+ translatePath: path,
6288
+ conditionalMembers: formStateRef.current ? getConditionalMembers(formStateRef.current) : []
6289
+ });
6290
+ },
6291
+ renderAsButton: true,
6292
+ disabled: fieldTranslate.translationLoading || readOnly
6293
+ }) : void 0, [openFieldTranslation, documentSchemaType, documentId, fieldTranslate.translationLoading, fieldTransEnabled, path, readOnly]);
6294
+ return useMemo(() => {
6295
+ return node$2({
6296
+ type: "group",
6297
+ icon: () => null,
6298
+ title: "Translation",
6299
+ children: [translateDocumentAction, translateFieldsAction].filter(c => !!c),
6300
+ expanded: true
6301
+ });
6302
+ }, [translateDocumentAction, translateFieldsAction]);
6303
+ }
6304
+ return void 0;
6305
+ }
6306
+ };
6307
+ function node$1(node2) {
6308
+ return node2;
6309
+ }
6310
+ const generateImagActions = {
6311
+ name: "sanity-assist-generate-image",
6312
+ useAction(props) {
6313
+ const pathKey = usePathKey(props.path);
6314
+ const {
6315
+ config
6316
+ } = useAiAssistanceConfig();
6317
+ const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
6318
+ const {
6319
+ generateImage,
6320
+ loading
6321
+ } = useGenerateImage(apiClient);
6322
+ const imageContext = useContext(ImageContext);
6323
+ if (imageContext && pathKey === (imageContext == null ? void 0 : imageContext.imageInstructionPath)) {
6324
+ const {
6325
+ documentId
6326
+ } = useAssistDocumentContext();
6327
+ return useMemo(() => {
6328
+ return node$1({
6329
+ type: "action",
6330
+ icon: loading ? () => /* @__PURE__ */jsx(Box, {
6331
+ style: {
6332
+ height: 17
6333
+ },
6334
+ children: /* @__PURE__ */jsx(Spinner, {
6335
+ style: {
6336
+ transform: "translateY(6px)"
6337
+ }
6338
+ })
6339
+ }) : ImageIcon,
6340
+ title: "Generate image from prompt",
6341
+ onAction: () => {
6342
+ if (loading) {
6343
+ return;
6344
+ }
6345
+ generateImage({
6346
+ path: pathKey,
6347
+ documentId: documentId != null ? documentId : ""
6348
+ });
6349
+ },
6350
+ renderAsButton: true,
6351
+ disabled: loading
6352
+ });
6353
+ }, [generateImage, pathKey, documentId, loading]);
6354
+ }
6355
+ return void 0;
6356
+ }
6357
+ };
4420
6358
  function node(node2) {
4421
6359
  return node2;
4422
6360
  }
@@ -4437,7 +6375,8 @@ const assistFieldActions = {
4437
6375
  documentOnChange,
4438
6376
  documentSchemaType,
4439
6377
  documentId,
4440
- selectedPath
6378
+ selectedPath,
6379
+ assistableDocumentId
4441
6380
  } =
4442
6381
  // document field actions do not have access to the document context
4443
6382
  // conditional hook _should_ be safe here since the logical path will be stable
@@ -4447,8 +6386,11 @@ const assistFieldActions = {
4447
6386
  // eslint-disable-next-line react-hooks/rules-of-hooks
4448
6387
  useAssistDocumentContext();
4449
6388
  const {
4450
- value: docValue
6389
+ value: docValue,
6390
+ formState
4451
6391
  } = useDocumentPane();
6392
+ const formStateRef = useRef(formState);
6393
+ formStateRef.current = formState;
4452
6394
  const currentUser = useCurrentUser();
4453
6395
  const isHidden = !assistDocument;
4454
6396
  const pathKey = usePathKey(props.path);
@@ -4462,7 +6404,7 @@ const assistFieldActions = {
4462
6404
  isDocAssistable: documentIsAssistable != null ? documentIsAssistable : false
4463
6405
  });
4464
6406
  const isSelectable = !!useSelectedField(documentSchemaType, typePath);
4465
- const assistSupported = useAssistSupported(props.path, schemaType) && isSelectable && isSchemaAssistEnabled(documentSchemaType);
6407
+ const assistSupported = useAssistSupported(props.path, schemaType) && isSelectable && isSchemaAssistEnabled(documentSchemaType) && schemaType.readOnly !== true;
4466
6408
  const fieldAssist = useMemo(() => {
4467
6409
  var _a;
4468
6410
  return ((_a = assistDocument == null ? void 0 : assistDocument.fields) != null ? _a : []).find(f => f.path === typePath || pathKey === documentRootKey && f.path === pathKey);
@@ -4472,6 +6414,13 @@ const assistFieldActions = {
4472
6414
  const isPathSelected = pathKey === selectedPath;
4473
6415
  const isSelected = isInspectorOpen && isPathSelected;
4474
6416
  const imageCaptionAction = generateCaptionsActions.useAction(props);
6417
+ const imageGenAction = generateImagActions.useAction(props);
6418
+ const translateAction = translateActions.useAction(typed({
6419
+ ...props,
6420
+ documentId: assistableDocumentId,
6421
+ documentIsAssistable,
6422
+ documentSchemaType
6423
+ }));
4475
6424
  const manageInstructions = useCallback(() => isSelected ? closeInspector(aiInspectorId) : openInspector(aiInspectorId, {
4476
6425
  [fieldPathParam]: pathKey,
4477
6426
  [instructionParam]: void 0
@@ -4485,7 +6434,8 @@ const assistFieldActions = {
4485
6434
  assistDocumentId,
4486
6435
  path: pathKey,
4487
6436
  typePath,
4488
- instruction
6437
+ instruction,
6438
+ conditionalMembers: formStateRef.current ? getConditionalMembers(formStateRef.current) : []
4489
6439
  });
4490
6440
  }, [requestRunInstruction, assistableDocId, pathKey, typePath, assistDocumentId, fieldAssistKey]);
4491
6441
  const privateInstructions = useMemo(() => {
@@ -4498,7 +6448,7 @@ const assistFieldActions = {
4498
6448
  }, [fieldAssist == null ? void 0 : fieldAssist.instructions]);
4499
6449
  const instructions = useMemo(() => [...privateInstructions, ...sharedInstructions], [privateInstructions, sharedInstructions]);
4500
6450
  const runInstructionsGroup = useMemo(() => {
4501
- return (instructions == null ? void 0 : instructions.length) || imageCaptionAction ? node({
6451
+ return (instructions == null ? void 0 : instructions.length) || imageCaptionAction || translateAction || imageGenAction ? node({
4502
6452
  type: "group",
4503
6453
  icon: () => null,
4504
6454
  title: "Run instructions",
@@ -4509,10 +6459,10 @@ const assistFieldActions = {
4509
6459
  hidden: isHidden,
4510
6460
  documentIsNew: !!documentIsNew,
4511
6461
  assistSupported
4512
- }))), imageCaptionAction].filter(Boolean),
6462
+ }))), imageCaptionAction, imageGenAction].filter(a => !!a),
4513
6463
  expanded: true
4514
6464
  }) : void 0;
4515
- }, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction]);
6465
+ }, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction, translateAction, imageGenAction]);
4516
6466
  const instructionsLength = (instructions == null ? void 0 : instructions.length) || 0;
4517
6467
  const manageInstructionsItem = useMemo(() => node({
4518
6468
  type: "action",
@@ -4525,13 +6475,13 @@ const assistFieldActions = {
4525
6475
  type: "group",
4526
6476
  icon: SparklesIcon,
4527
6477
  title: pluginTitleShort,
4528
- children: [runInstructionsGroup, assistSupported && manageInstructionsItem].filter(c => !!c),
6478
+ children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c).filter(c => c.type === "group" ? c.children.length : true),
4529
6479
  expanded: false,
4530
6480
  renderAsButton: true,
4531
- hidden: !assistSupported && !imageCaptionAction
6481
+ hidden: !assistSupported && !imageCaptionAction && !translateAction && !imageGenAction
4532
6482
  }), [
4533
6483
  //documentIsNew,
4534
- runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction]);
6484
+ runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction, translateAction, imageGenAction]);
4535
6485
  const emptyAction = useMemo(() => node({
4536
6486
  type: "action",
4537
6487
  hidden: !assistSupported,
@@ -4541,7 +6491,7 @@ const assistFieldActions = {
4541
6491
  title: pluginTitleShort,
4542
6492
  selected: isSelected
4543
6493
  }), [assistSupported, manageInstructions, isSelected]);
4544
- if (instructionsLength === 0 && !imageCaptionAction) {
6494
+ if (instructionsLength === 0 && !imageCaptionAction && !translateAction && !imageGenAction) {
4545
6495
  return emptyAction;
4546
6496
  }
4547
6497
  return group;
@@ -4561,9 +6511,7 @@ function instructionItem(props) {
4561
6511
  iconRight: isPrivate ? PrivateIcon : void 0,
4562
6512
  title: getInstructionTitle(instruction),
4563
6513
  onAction: () => onInstructionAction(instruction),
4564
- disabled: assistSupported ? false : {
4565
- reason: "".concat(pluginTitle, " is not supported for this field")
4566
- },
6514
+ disabled: !assistSupported,
4567
6515
  hidden
4568
6516
  });
4569
6517
  }
@@ -4640,7 +6588,7 @@ function useInstructionToaster(documentId, documentSchemaType) {
4640
6588
  }
4641
6589
  function AssistDocumentInputWrapper(props) {
4642
6590
  var _a;
4643
- if (!isType(props.schemaType, "document") && props.id !== "root") {
6591
+ if (!isType(props.schemaType, "document") && props.id !== "root" && props.id !== assistFormId) {
4644
6592
  return /* @__PURE__ */jsx(AssistInput, {
4645
6593
  ...props
4646
6594
  });
@@ -4654,18 +6602,34 @@ function AssistDocumentInputWrapper(props) {
4654
6602
  documentId
4655
6603
  });
4656
6604
  }
4657
- function AssistDocumentInput(_ref16) {
6605
+ function AssistDocumentInput(_ref24) {
4658
6606
  let {
4659
6607
  documentId,
4660
6608
  ...props
4661
- } = _ref16;
6609
+ } = _ref24;
4662
6610
  useInstructionToaster(documentId, props.schemaType);
6611
+ const schemaType = useMemo(() => {
6612
+ if (props.schemaType.name !== assistDocumentTypeName) {
6613
+ return props.schemaType;
6614
+ }
6615
+ return {
6616
+ ...props.schemaType,
6617
+ type: {
6618
+ ...props.schemaType.type,
6619
+ // compatability with i18nArrays plugin that requires this to be document
6620
+ name: "document"
6621
+ }
6622
+ };
6623
+ }, [props.schemaType]);
4663
6624
  return /* @__PURE__ */jsx(FirstAssistedPathProvider, {
4664
6625
  members: props.members,
4665
6626
  children: /* @__PURE__ */jsx(AssistDocumentContextProvider, {
4666
- schemaType: props.schemaType,
6627
+ schemaType,
4667
6628
  documentId,
4668
- children: props.renderDefault(props)
6629
+ children: props.renderDefault({
6630
+ ...props,
6631
+ schemaType
6632
+ })
4669
6633
  })
4670
6634
  });
4671
6635
  }
@@ -4703,11 +6667,11 @@ function AssistDocumentPresence(props) {
4703
6667
  const anyPresence2 = (_b = (_a = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _a.filter(run => !run.ended && !run.reason)) == null ? void 0 : _b.flatMap(run => {
4704
6668
  var _a2;
4705
6669
  return (_a2 = run.presence) != null ? _a2 : [];
4706
- }).find(f => f.started && /* @__PURE__ */new Date().getTime() - new Date(f.started).getTime() < 3e4);
6670
+ }).find(f => f.started && ( /* @__PURE__ */new Date()).getTime() - new Date(f.started).getTime() < 3e4);
4707
6671
  if (anyPresence2) {
4708
6672
  return aiPresence(anyPresence2, []);
4709
6673
  }
4710
- const anyRun = (_d = (_c = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _c.filter(run => !run.ended && !run.reason)) == null ? void 0 : _d.find(f => f.started && /* @__PURE__ */new Date().getTime() - new Date(f.started).getTime() < 3e4);
6674
+ const anyRun = (_d = (_c = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _c.filter(run => !run.ended && !run.reason)) == null ? void 0 : _d.find(f => f.started && ( /* @__PURE__ */new Date()).getTime() - new Date(f.started).getTime() < 3e4);
4711
6675
  return anyRun ? aiPresence({
4712
6676
  started: anyRun.started,
4713
6677
  path: documentRootKey,
@@ -4736,31 +6700,41 @@ const assist = definePlugin(config => {
4736
6700
  schema: {
4737
6701
  types: schemaTypes
4738
6702
  },
6703
+ i18n: {
6704
+ bundles: [{}]
6705
+ },
4739
6706
  document: {
4740
6707
  inspectors: (prev, context) => {
4741
- const docSchema = context.schema.get(context.documentType);
6708
+ const documentType = context.documentType;
6709
+ const docSchema = context.schema.get(documentType);
4742
6710
  if (docSchema && isSchemaAssistEnabled(docSchema)) {
4743
6711
  return [...prev, assistInspector];
4744
6712
  }
4745
6713
  return prev;
4746
6714
  },
4747
- unstable_fieldActions: (prev, _ref17) => {
6715
+ unstable_fieldActions: (prev, _ref25) => {
4748
6716
  let {
4749
6717
  documentType,
4750
6718
  schema
4751
- } = _ref17;
6719
+ } = _ref25;
6720
+ if (documentType === assistDocumentTypeName) {
6721
+ return [];
6722
+ }
4752
6723
  const docSchema = schema.get(documentType);
4753
6724
  if (docSchema && isSchemaAssistEnabled(docSchema)) {
4754
6725
  return [...prev, assistFieldActions];
4755
6726
  }
4756
6727
  return prev;
4757
6728
  },
4758
- unstable_languageFilter: (prev, _ref18) => {
6729
+ unstable_languageFilter: (prev, _ref26) => {
4759
6730
  let {
4760
6731
  documentId,
4761
6732
  schema,
4762
6733
  schemaType
4763
- } = _ref18;
6734
+ } = _ref26;
6735
+ if (schemaType === assistDocumentTypeName) {
6736
+ return [];
6737
+ }
4764
6738
  const docSchema = schema.get(schemaType);
4765
6739
  if (docSchema && isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema)) {
4766
6740
  return [...prev, createAssistDocumentPresence(documentId, docSchema)];
@@ -4814,5 +6788,5 @@ const assist = definePlugin(config => {
4814
6788
  })()]
4815
6789
  };
4816
6790
  });
4817
- export { SchemaTypeTool, assist, contextDocumentTypeName };
6791
+ export { SchemaTypeTool, assist, contextDocumentTypeName, defaultLanguageOutputs };
4818
6792
  //# sourceMappingURL=index.esm.js.map