@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
@@ -0,0 +1,186 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks */
2
+ import {
3
+ DocumentFieldAction,
4
+ DocumentFieldActionGroup,
5
+ DocumentFieldActionItem,
6
+ DocumentFieldActionProps,
7
+ ObjectSchemaType,
8
+ } from 'sanity'
9
+ import {TranslateIcon} from '@sanity/icons'
10
+ import {useMemo, useRef} from 'react'
11
+ import {useApiClient, useTranslate} from '../useApiClient'
12
+ import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
13
+ import {Box, Spinner} from '@sanity/ui'
14
+ import {isAssistSupported} from '../helpers/assistSupported'
15
+ import {useDocumentPane} from 'sanity/desk'
16
+ import {useFieldTranslation} from './FieldTranslationProvider'
17
+ import {useDraftDelayedTask} from '../assistDocument/RequestRunInstructionProvider'
18
+ import {AssistOptions} from '../schemas/typeDefExtensions'
19
+ import {getConditionalMembers} from '../helpers/conditionalMembers'
20
+
21
+ function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
22
+ return node
23
+ }
24
+
25
+ export type TranslateProps = DocumentFieldActionProps & {
26
+ documentIsAssistable?: boolean
27
+ documentSchemaType?: ObjectSchemaType
28
+ }
29
+ export const translateActions: DocumentFieldAction = {
30
+ name: 'sanity-assist-translate',
31
+ useAction(props: TranslateProps) {
32
+ const {config, status} = useAiAssistanceConfig()
33
+ const apiClient = useApiClient(config?.__customApiClient)
34
+
35
+ const {
36
+ schemaType: fieldSchemaType,
37
+ path,
38
+ documentId,
39
+ documentSchemaType,
40
+ documentIsAssistable,
41
+ } = props
42
+ const isDocumentLevel = path.length === 0
43
+ const readOnly = fieldSchemaType.readOnly === true
44
+
45
+ const docTransTypes = config.translate?.document?.documentTypes
46
+ const options = fieldSchemaType?.options as AssistOptions | undefined
47
+ const addFieldAction = isDocumentLevel || options?.aiAssist?.translateAction
48
+
49
+ const fieldTransEnabled =
50
+ addFieldAction &&
51
+ status?.initialized &&
52
+ documentSchemaType &&
53
+ config.translate?.field?.documentTypes?.includes(documentSchemaType.name)
54
+ const documentTranslationEnabled =
55
+ addFieldAction &&
56
+ status?.initialized &&
57
+ documentSchemaType &&
58
+ ((!docTransTypes && isAssistSupported(fieldSchemaType)) ||
59
+ docTransTypes?.includes(documentSchemaType.name))
60
+
61
+ // these checks are stable (ie, does not change after mount), so not breaking rules of hooks
62
+ if (documentSchemaType && (documentTranslationEnabled || fieldTransEnabled)) {
63
+ const {value: documentValue, onChange: documentOnChange, formState} = useDocumentPane()
64
+ const docRef = useRef(documentValue)
65
+ docRef.current = documentValue
66
+ const formStateRef = useRef(formState)
67
+ formStateRef.current = formState
68
+
69
+ const translationApi = useTranslate(apiClient)
70
+ const translate = useDraftDelayedTask({
71
+ documentOnChange,
72
+ isDocAssistable: documentIsAssistable ?? false,
73
+ task: translationApi.translate,
74
+ })
75
+
76
+ const languagePath = config.translate?.document?.languageField
77
+
78
+ // if this is true, it is stable, and not breaking rules of hooks
79
+ const translateDocumentAction = useMemo(() => {
80
+ if (!languagePath || !documentTranslationEnabled) {
81
+ return undefined
82
+ }
83
+ const title = path.length ? `Translate` : `Translate document`
84
+ return node({
85
+ type: 'action',
86
+ icon: translationApi.loading
87
+ ? () => (
88
+ <Box style={{height: 17}}>
89
+ <Spinner style={{transform: 'translateY(6px)'}} />
90
+ </Box>
91
+ )
92
+ : TranslateIcon,
93
+ title,
94
+ onAction: () => {
95
+ if (translationApi.loading || !languagePath || !documentId) {
96
+ return
97
+ }
98
+ translate({
99
+ languagePath,
100
+ translatePath: path,
101
+ documentId: documentId ?? '',
102
+ conditionalMembers: formStateRef.current
103
+ ? getConditionalMembers(formStateRef.current)
104
+ : [],
105
+ })
106
+ },
107
+ renderAsButton: true,
108
+ disabled: translationApi.loading || readOnly,
109
+ })
110
+ }, [
111
+ languagePath,
112
+ translate,
113
+ documentId,
114
+ translationApi.loading,
115
+ documentTranslationEnabled,
116
+ path,
117
+ readOnly,
118
+ ])
119
+ const fieldTranslate = useFieldTranslation()
120
+ const openFieldTranslation = useDraftDelayedTask({
121
+ documentOnChange,
122
+ isDocAssistable: documentIsAssistable ?? false,
123
+ task: fieldTranslate.openFieldTranslation,
124
+ })
125
+
126
+ const translateFieldsAction = useMemo(
127
+ () =>
128
+ fieldTransEnabled
129
+ ? node({
130
+ type: 'action',
131
+ icon: fieldTranslate.translationLoading
132
+ ? () => (
133
+ <Box style={{height: 17}}>
134
+ <Spinner style={{transform: 'translateY(6px)'}} />
135
+ </Box>
136
+ )
137
+ : TranslateIcon,
138
+ title: `Translate fields...`,
139
+ onAction: () => {
140
+ if (fieldTranslate.translationLoading || !documentId) {
141
+ return
142
+ }
143
+ if (formStateRef.current) {
144
+ getConditionalMembers(formStateRef.current)
145
+ }
146
+ openFieldTranslation({
147
+ document: docRef.current,
148
+ documentSchema: documentSchemaType,
149
+ translatePath: path,
150
+ conditionalMembers: formStateRef.current
151
+ ? getConditionalMembers(formStateRef.current)
152
+ : [],
153
+ })
154
+ },
155
+ renderAsButton: true,
156
+ disabled: fieldTranslate.translationLoading || readOnly,
157
+ })
158
+ : undefined,
159
+ [
160
+ openFieldTranslation,
161
+ documentSchemaType,
162
+ documentId,
163
+ fieldTranslate.translationLoading,
164
+ fieldTransEnabled,
165
+ path,
166
+ readOnly,
167
+ ]
168
+ )
169
+
170
+ // eslint-disable-next-line react-hooks/rules-of-hooks
171
+ return useMemo(() => {
172
+ return node({
173
+ type: 'group',
174
+ icon: () => null,
175
+ title: 'Translation',
176
+ children: [translateDocumentAction, translateFieldsAction].filter(
177
+ (c): c is DocumentFieldActionItem => !!c
178
+ ),
179
+ expanded: true,
180
+ })
181
+ }, [translateDocumentAction, translateFieldsAction])
182
+ }
183
+ // works but not supported by types
184
+ return undefined as unknown as DocumentFieldActionItem
185
+ },
186
+ }
@@ -0,0 +1,160 @@
1
+ import {Path, SanityClient, SchemaType} from 'sanity'
2
+
3
+ export interface Language {
4
+ id: string
5
+ title?: string
6
+ }
7
+
8
+ export interface DocumentMember {
9
+ schemaType: SchemaType
10
+ path: Path
11
+ name: string
12
+ value: unknown
13
+ }
14
+
15
+ export interface TranslationOutput {
16
+ /** Language id */
17
+ id: string
18
+ outputPath: Path
19
+ }
20
+
21
+ export type TranslationOutputsFunction = (
22
+ documentMember: DocumentMember,
23
+ enclosingType: SchemaType,
24
+ translateFromLanguageId: string,
25
+ translateToLanguageIds: string[]
26
+ ) => TranslationOutput[] | undefined
27
+
28
+ export type LanguageCallback = (
29
+ client: SanityClient,
30
+ selectedLanguageParams: Record<string, unknown>
31
+ ) => Promise<Language[]>
32
+
33
+ export interface FieldTranslationConfig {
34
+ /**
35
+ * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
36
+ *
37
+ * If defined, matching document will get a "Translate fields" instruction added.
38
+ **/
39
+ documentTypes?: string[]
40
+
41
+ /**
42
+ *
43
+ * Used for display strings in the Studio, and to determine languages for field level translations
44
+ *
45
+ * If the studio is using the sanity-plugin-internationalized-array plugin, this
46
+ * should be set to the same configuration.
47
+ */
48
+ languages: Language[] | LanguageCallback
49
+
50
+ /**
51
+ * API version for client passed to LanguageCallback for languages
52
+ * https://www.sanity.io/docs/api-versioning
53
+ * @defaultValue '2022-11-27'
54
+ */
55
+ apiVersion?: string
56
+
57
+ /**
58
+ * Specify fields that should be available in the languages callback:
59
+ * ```tsx
60
+ * {
61
+ * select: {
62
+ * markets: 'markets'
63
+ * },
64
+ * languages: (client, {markets}) =>
65
+ * client.fetch('*[_type == "language" && market in $markets]{id,title}', {markets})
66
+ * }
67
+ * ```
68
+ *
69
+ * If the studio is using the sanity-plugin-internationalized-array plugin, this
70
+ * should be set to the same configuration.
71
+ */
72
+ selectLanguageParams?: Record<string, string>
73
+
74
+ /**
75
+ * `translationOutputs` is used when the "Translate fields" instruction is started by a Studio user.
76
+ *
77
+ * It determines the relationships between document paths: Given a document path and a language, into which
78
+ * sibling paths should translations be output.
79
+
80
+ *
81
+ * `translationOutputs` is invoked once per path in the document (limited to a depth of 6), with the following:
82
+ *
83
+ * * `documentMember` - the field or array item for a given path; contains the path and its schemaType,
84
+ * * `enclosingType` - the schema type of parent holding the member
85
+ * * `translateFromLanguageId` - the languageId for the language the user want to translate from
86
+ * * `translateToLanguageIds` - all languageIds the user can translate to
87
+ *
88
+ * The function should return a `TranslationOutput[]` array that contains all the paths where translations from
89
+ * documentMember language (translateFromLanguageId) should be output.
90
+ *
91
+ * The function should return `undefined` for all documentMembers that should not be directly translated,
92
+ * or are nested fields under a translated path.
93
+ *
94
+ * ## Default function
95
+ *
96
+ * The default function for `translationOutputs` is configured to be automatically compatible with sanity-plugin-internationalized-array
97
+ * and object types prefixed with "locale".
98
+ *
99
+ * See <link to source for defaultTranslationOutputs> implementation details.
100
+ *
101
+ * ## Example
102
+ * A document has the following document members:
103
+ * * `{path: 'localeObject.en', schemaType: ObjectSchemaType}`
104
+ * * `{path: 'localeObject.en.title', schemaType: StringSchemaType}`
105
+ * * `{path: 'localeObject.de', schemaType: ObjectSchemaType}`,
106
+ * * `{path: 'localeObject.de.title', schemaType: StringSchemaType}`
107
+ *
108
+ * `translationOutputs` for invoked with `translateFromLanguageId` `en`,
109
+ * should only return [{id: 'de', outputPath: 'localeObject.de'}] for the `'localeObject.en'` path,
110
+ * and undefined for all the other members.
111
+ *
112
+ * ### Example implementation
113
+ * ```ts
114
+ * function translationOutputs(member, enclosingType, translateFromLanguageId, translateToLanguageIds)
115
+ * if (enclosingType.jsonType === 'object' && enclosingType.name.startsWith('locale') && translateFromLanguageId === member.name) {
116
+ * return translateToLanguageIds.map((translateToId) => ({
117
+ * id: translateToId,
118
+ * outputPath: [...member.path.slice(0, -1), translateToId],
119
+ * }))
120
+ * }
121
+ * return undefined
122
+ * }
123
+ * ```
124
+ **/
125
+ translationOutputs?: TranslationOutputsFunction
126
+ }
127
+
128
+ export interface DocumentTranslationConfig {
129
+ /**
130
+ * Path to language field in documents. Can be a hidden field.
131
+ * For instance: 'config.language'
132
+ *
133
+ * For projects that use the `@sanity/document-internationalization` plugin,
134
+ * this should be the same as `languageField` config for that plugin.
135
+ *
136
+ * Default: 'language'
137
+ */
138
+ languageField: string
139
+
140
+ /**
141
+ * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
142
+ *
143
+ * If defined, this property will add a translate instruction to these document types.
144
+ * If undefined, the instruction will be added to all documents with aiAssistance enabled and a field matching `documentLanguageField` config.
145
+ *
146
+ * Documents with translation support will get a "Translate document>" instruction added.
147
+ **/
148
+ documentTypes?: string[]
149
+ }
150
+
151
+ export interface TranslationConfig {
152
+ /**
153
+ * Config for document types with fields in multiple languages in the same document.
154
+ */
155
+ field?: FieldTranslationConfig
156
+ /**
157
+ * Config for document types with a single language field that determines the language for the whole document.
158
+ */
159
+ document?: DocumentTranslationConfig
160
+ }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {SanityDocument, ValidationMarker} from 'sanity'
1
+ import {SanityDocument} from 'sanity'
2
2
  import {PortableTextBlock, PortableTextMarkDefinition, PortableTextSpan} from '@portabletext/types'
3
3
 
4
4
  //id prefixes
@@ -26,6 +26,9 @@ export const fieldPresenceTypeName = 'sanity.assist.instructionTask.presence' as
26
26
  export const assistSerializedTypeName = 'sanity.assist.serialized.type' as const
27
27
  export const assistSerializedFieldTypeName = 'sanity.assist.serialized.field' as const
28
28
 
29
+ export const outputFieldTypeName = 'sanity.assist.output.field' as const
30
+ export const outputTypeTypeName = 'sanity.assist.output.type' as const
31
+
29
32
  //url params
30
33
  export const inspectParam = 'inspect' as const
31
34
  export const fieldPathParam = 'pathKey' as const
@@ -34,27 +37,29 @@ export const instructionParam = 'instruction' as const
34
37
  // other constants
35
38
  export const documentRootKey = '<document>'
36
39
 
37
- export interface SerializedSchemaMember {
40
+ export type SerializedSchemaMember = Omit<SerializedSchemaType, 'name' | '_type'> & {
38
41
  _type?: typeof assistSerializedFieldTypeName
39
- type: string
40
- name: string
41
- title?: string
42
- values?: string[]
43
- of?: SerializedSchemaMember[]
44
- to?: {type: string}[]
42
+ name?: string
45
43
  }
46
44
 
47
45
  export interface SerializedSchemaType {
48
46
  _type?: typeof assistSerializedTypeName
49
47
  _id?: string
50
48
  type: string
49
+ name: string
51
50
  title?: string
52
- name?: string
53
51
  fields?: SerializedSchemaMember[]
54
- of?: {type: string}[]
55
- to?: {type: string}[]
52
+ of?: SerializedSchemaMember[]
53
+ to?: SerializedSchemaMember[]
54
+ annotations?: SerializedSchemaMember[]
55
+ inlineOf?: SerializedSchemaMember[]
56
+ values?: string[] | {value: string; title?: string}[]
57
+ hidden?: boolean | 'function'
58
+ readOnly?: boolean | 'function'
56
59
  options?: {
60
+ /** equivalent to options.aiAssist.imageDescriptionField - not renamed in the api for backwards compatability */
57
61
  imagePromptField?: string
62
+ embeddingsIndex?: string
58
63
  }
59
64
  }
60
65
 
@@ -149,10 +154,10 @@ export interface StudioInstruction {
149
154
  userId?: string
150
155
  title?: string
151
156
  placeholder?: string
157
+ output?: (OutputFieldItem | OutputTypeItem)[]
152
158
 
153
159
  //added after query / synthetic fields
154
160
  tasks?: InstructionTask[]
155
- validation?: ValidationMarker[]
156
161
  }
157
162
 
158
163
  export interface AssistTasksStatus {
@@ -166,3 +171,19 @@ export interface AssistInspectorRouteParams {
166
171
  [fieldPathParam]?: string
167
172
  [instructionParam]?: string
168
173
  }
174
+
175
+ export interface OutputFieldItem {
176
+ _type: typeof outputFieldTypeName
177
+ _key: string
178
+ //path relative to the field the instruction is for (same as _key)
179
+ relativePath?: string
180
+ }
181
+
182
+ export interface OutputTypeItem {
183
+ _type: typeof outputTypeTypeName
184
+ _key: string
185
+ /* array item type name */
186
+ type?: string
187
+ //path relative to the array-field the instruction is for, can be empty string (the array itself, same as _key)
188
+ relativePath?: string
189
+ }
@@ -1,8 +1,11 @@
1
- import {useClient, useCurrentUser, useSchema} from 'sanity'
1
+ import {Path, pathToString, useClient, useCurrentUser, useSchema} from 'sanity'
2
2
  import {useCallback, useMemo, useState} from 'react'
3
3
  import {serializeSchema} from './schemas/serialize/serializeSchema'
4
4
  import {useToast} from '@sanity/ui'
5
5
  import {SanityClient} from '@sanity/client'
6
+ import {FieldLanguageMap} from './translate/paths'
7
+ import {documentRootKey} from './types'
8
+ import {ConditionalMemberState} from './helpers/conditionalMembers'
6
9
 
7
10
  export interface UserTextInstance {
8
11
  blockKey: string
@@ -17,6 +20,7 @@ export interface RunInstructionRequest {
17
20
  instructionKey: string
18
21
  userId?: string
19
22
  userTexts?: UserTextInstance[]
23
+ conditionalMembers?: ConditionalMemberState[]
20
24
  }
21
25
 
22
26
  export interface InstructStatus {
@@ -25,6 +29,14 @@ export interface InstructStatus {
25
29
  validToken: boolean
26
30
  }
27
31
 
32
+ export interface TranslateRequest {
33
+ documentId: string
34
+ translatePath: Path
35
+ languagePath?: string
36
+ fieldLanguageMap?: FieldLanguageMap[]
37
+ conditionalMembers?: ConditionalMemberState[]
38
+ }
39
+
28
40
  const basePath = '/assist/tasks/instruction'
29
41
 
30
42
  export function useApiClient(customApiClient?: (defaultClient: SanityClient) => SanityClient) {
@@ -35,6 +47,69 @@ export function useApiClient(customApiClient?: (defaultClient: SanityClient) =>
35
47
  )
36
48
  }
37
49
 
50
+ export function useTranslate(apiClient: SanityClient) {
51
+ const [loading, setLoading] = useState(false)
52
+ const user = useCurrentUser()
53
+ const schema = useSchema()
54
+ const types = useMemo(() => serializeSchema(schema, {leanFormat: true}), [schema])
55
+ const toast = useToast()
56
+
57
+ const translate = useCallback(
58
+ ({
59
+ documentId,
60
+ languagePath,
61
+ translatePath,
62
+ fieldLanguageMap,
63
+ conditionalMembers,
64
+ }: TranslateRequest) => {
65
+ setLoading(true)
66
+
67
+ return apiClient
68
+ .request({
69
+ method: 'POST',
70
+ url: `/assist/tasks/translate/${apiClient.config().dataset}?projectId=${
71
+ apiClient.config().projectId
72
+ }`,
73
+ body: {
74
+ documentId,
75
+ types,
76
+ languagePath,
77
+ fieldLanguageMap,
78
+ conditionalMembers,
79
+ translatePath:
80
+ translatePath.length === 0 ? documentRootKey : pathToString(translatePath),
81
+ userId: user?.id,
82
+ },
83
+ })
84
+ .catch((e) => {
85
+ toast.push({
86
+ status: 'error',
87
+ title: 'Translate failed',
88
+ description: e.message,
89
+ })
90
+ setLoading(false)
91
+ throw e
92
+ })
93
+ .finally(() => {
94
+ // adding some artificial delay here
95
+ // server responds with 201 then proceeds; we dont need to allow spamming the button
96
+ setTimeout(() => {
97
+ setLoading(false)
98
+ }, 2000)
99
+ })
100
+ },
101
+ [setLoading, apiClient, toast, user, types]
102
+ )
103
+
104
+ return useMemo(
105
+ () => ({
106
+ translate,
107
+ loading,
108
+ }),
109
+ [translate, loading]
110
+ )
111
+ }
112
+
38
113
  export function useGenerateCaption(apiClient: SanityClient) {
39
114
  const [loading, setLoading] = useState(false)
40
115
  const user = useCurrentUser()
@@ -62,7 +137,7 @@ export function useGenerateCaption(apiClient: SanityClient) {
62
137
  .catch((e) => {
63
138
  toast.push({
64
139
  status: 'error',
65
- title: 'Generate caption failed',
140
+ title: 'Generate image description failed',
66
141
  description: e.message,
67
142
  })
68
143
  setLoading(false)
@@ -88,6 +163,59 @@ export function useGenerateCaption(apiClient: SanityClient) {
88
163
  )
89
164
  }
90
165
 
166
+ export function useGenerateImage(apiClient: SanityClient) {
167
+ const [loading, setLoading] = useState(false)
168
+ const user = useCurrentUser()
169
+ const schema = useSchema()
170
+ const types = useMemo(() => serializeSchema(schema, {leanFormat: true}), [schema])
171
+ const toast = useToast()
172
+
173
+ const generateImage = useCallback(
174
+ ({path, documentId}: {path: string; documentId: string}) => {
175
+ setLoading(true)
176
+
177
+ return apiClient
178
+ .request({
179
+ method: 'POST',
180
+ url: `/assist/tasks/generate-image/${apiClient.config().dataset}?projectId=${
181
+ apiClient.config().projectId
182
+ }`,
183
+ body: {
184
+ path,
185
+ documentId,
186
+ types,
187
+ userId: user?.id,
188
+ },
189
+ })
190
+ .catch((e) => {
191
+ toast.push({
192
+ status: 'error',
193
+ title: 'Generate image from prompt failed',
194
+ description: e.message,
195
+ })
196
+ setLoading(false)
197
+ throw e
198
+ })
199
+ .finally(() => {
200
+ // adding some artificial delay here
201
+ // server responds with 201 then proceeds; we dont need to allow spamming the button
202
+ setTimeout(() => {
203
+ setLoading(false)
204
+ }, 2000)
205
+ })
206
+ },
207
+ [setLoading, apiClient, toast, user, types]
208
+ )
209
+
210
+ return useMemo(
211
+ () => ({
212
+ generateImage,
213
+ loading,
214
+ }),
215
+ [generateImage, loading]
216
+ )
217
+ }
218
+
91
219
  export function useGetInstructStatus(apiClient: SanityClient) {
92
220
  const [loading, setLoading] = useState(true)
93
221