@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/README.md CHANGED
@@ -16,8 +16,20 @@
16
16
  - [Disable for a field](#disable-for-a-field)
17
17
  - [Disable for an array type](#disable-for-an-array-type)
18
18
  - [Unsupported types](#unsupported-types)
19
+ - [Hidden and readOnly fields](#hidden-and-readonly-fields)
20
+ - [Reference support](#reference-support)
19
21
  - [Troubleshooting](#troubleshooting)
20
22
  - [Included document types](#included-document-types)
23
+ - [Field and type filters](#field-and-type-filters)
24
+ - [Image description generation](#image-description-generation)
25
+ - [Image generation](#image-generation)
26
+ - [Full document translation](#full-document-translation)
27
+ - [What it solves](#what-ai-assist-full-document-translations-solves)
28
+ - [Configure](#configure-document-translations)
29
+ - [Field level translations](#field-level-translations)
30
+ - [What it solves](#what-ai-assist-field-level-translations-solves)
31
+ - [Configure](#configure-field-translations)
32
+ - [Adding translation actions to fields](#adding-translation-actions-to-fields)
21
33
  - [License](#license)
22
34
  - [Develop \& test](#develop--test)
23
35
  - [Release new version](#release-new-version)
@@ -43,7 +55,7 @@ In your Studio project folder, install the following plugin dependency:
43
55
  npm install @sanity/assist sanity@latest
44
56
  ```
45
57
 
46
- This plugin requires `sanity` version `3.16.0` or greater.
58
+ This plugin requires `sanity` version `3.26` or greater.
47
59
 
48
60
  ## Setup
49
61
 
@@ -117,7 +129,7 @@ defineType({
117
129
  name: 'policy',
118
130
  type: 'document',
119
131
  options: {
120
- aiWritingAssistance: {exclude: true}
132
+ aiAssist: {exclude: true}
121
133
  },
122
134
  fields: [
123
135
  // ...
@@ -137,7 +149,7 @@ defineType({
137
149
  name: 'sku',
138
150
  type: 'string',
139
151
  options: {
140
- aiWritingAssistance: {exclude: true}
152
+ aiAssist: {exclude: true}
141
153
  }
142
154
  })
143
155
  ]
@@ -156,7 +168,7 @@ defineType({
156
168
  defineArrayMember({
157
169
  type: 'customProduct',
158
170
  options: {
159
- aiWritingAssistance: {exclude: true}
171
+ aiAssist: {exclude: true}
160
172
  }
161
173
  })
162
174
  ]
@@ -167,22 +179,71 @@ defineType({
167
179
 
168
180
  The following types are not supported, and behave as excluded types:
169
181
  * [Number](https://www.sanity.io/docs/number-type)
170
- * [Reference](https://www.sanity.io/docs/reference-type)
171
182
  * [Slug](https://www.sanity.io/docs/slug-type)
172
183
  * [Url](https://www.sanity.io/docs/url-type)
173
184
  * [Date](https://www.sanity.io/docs/date-type)
174
185
  * [Datetime](https://www.sanity.io/docs/datetime-type)
175
186
  * [Image](https://www.sanity.io/docs/image-type) (supported when image has custom fields)
176
187
  * [File](https://www.sanity.io/docs/file-type) (never supported, even when file has custom fields)
177
-
178
- Types and fields with `hidden` or `readonly` with a truthy value (`true` or `function`) are not supported.
179
- (Hidden and readOnly fields can be referenced in instructions still)
188
+ * [Reference](https://www.sanity.io/docs/reference-type) (supported when configured with embeddingsIndex)
180
189
 
181
190
  Fields with these types will not be changed by the assistant, do not have AI Assist actions, and cannot be referenced in instructions.
182
191
 
183
192
  Objects where all fields are excluded or unsupported and arrays where all member types are excluded or unsupported
184
193
  will also be excluded.
185
194
 
195
+ ### Hidden and readOnly fields
196
+
197
+ In AI Assist 2.0 and later, conditionally `hidden` and `readOnly` fields can have instructions.
198
+ These fields can be written to by an instruction, as long as the field is non-hidden and writable when the instruction is started.
199
+
200
+ Fields with `hidden` or `readOnly` set to literal `true` will be skipped by AI Assist.
201
+
202
+ *Note*: An instruction will not re-evaluate these states during a run.
203
+ Ie, if an instructions writes to a field that will make another field in the studio readonly or hidden,
204
+ the running instruction will still consider these as if in their original state.
205
+
206
+ If it is essential that AI Assist *never* writes to a conditional field,
207
+ it should be marked with `options.aiAssist.exclude: true`.
208
+
209
+ ### Reference support
210
+
211
+ #### Create an Embeddings-index
212
+ To enable AI assist for references, first, your project must have an existing [embeddings-index](https://www.sanity.io/docs/embeddings-index-api-overview)
213
+ with the documents it should be able to reference.
214
+
215
+ You can manage your indexes directly in the studio using the [Embeddings Index Dashboard plugin](https://github.com/sanity-io/embeddings-index-ui#embeddings-index-api-dashboard-for-sanity-studio).
216
+
217
+ #### Set schema options
218
+ Set `options.aiAssist.embeddingsIndex` for reference fields/types you want to enable reference instructions for.
219
+ Reference fields with this options set can have instructions attached to them, and will be visited when running instructions for object fields and arrays.
220
+
221
+ AI assist will use the embeddings-index, filtered by the types allowed by the reference to look up contextually relevant references.
222
+ For arrays or portable text fields with references, one more references can be added. Use the instruction text to control this.
223
+
224
+ Example:
225
+
226
+ ```ts
227
+ import {defineArrayMember} from 'sanity'
228
+
229
+ defineField({
230
+ type: 'reference',
231
+ name: 'articleReference',
232
+ title: 'Article referene',
233
+ to: [ { type: 'article'} ],
234
+ options: {
235
+ aiAssist: {
236
+ embeddingsIndex: 'article-index'
237
+ },
238
+ },
239
+ })
240
+ ```
241
+
242
+ An example instruction attached to this field could be:
243
+ `Given <Document field: Title> suggest a related article`
244
+
245
+ Running it would use the `article-index` to find an related article based on the current document title.
246
+
186
247
  ### Troubleshooting
187
248
 
188
249
  There are limits to how much text the AI can process when processing an instruction. Under the hood, the AI Assist will add information about your schema, which adds to what's commonly referred to as “the context window.”
@@ -191,6 +252,8 @@ If you have a very large schema (that is, many document and field types), it can
191
252
 
192
253
  We recommend excluding any and all types which rarely would benefit from automated workflows. A quick win is typically to exclude array types. It can be a good idea to exclude most non-block types from Portable Text arrays. This will ensure that the Sanity Assist outputs mostly formatted text.
193
254
 
255
+ It is also possible to exclude fields/types when creating an instruction. See [Field and type filters](#field-and-type-filters) for more.
256
+
194
257
  ## Included document types
195
258
 
196
259
  This plugin adds an `AI Context` document type.
@@ -206,20 +269,21 @@ import {contextDocumentTypeName} from '@sanity/assist'
206
269
  S.documentTypeListItem(contextDocumentTypeName)
207
270
  ```
208
271
 
209
- ## Caveats
272
+ ## Field and type filters
210
273
 
211
- Large Language Models (LLMs) are a new technology. Constraints and limitations are still being explored,
212
- but some common caveats to the field that you may run into using AI Assist are:
274
+ When creating instructions for a document, objects fields, array fields or portable text fields, you can explicitly control what will be visited by AI Assist.
275
+ By default, all fields and types configured for assist will be included.
213
276
 
214
- * Limits to instruction length: Long instructions on deep content structures may exhaust model context
215
- * Timeouts: To be able to write structured content, we're using the largest language models - long-running results may time out or intermittently fail
216
- * Limited capacity: The underlying LLM APIs used by AI Assist are resource constrained
277
+ Opting out fields/types per instruction is done using the respective field/type filter checkboxes under the instruction.
278
+ When using these filters, it is not necessary to tell Assist what to include in the instruction text itself.
217
279
 
218
- ## Other features
280
+ Note that if the schema targeted by the instruction changes, the following behavior applies:
281
+ * instructions that included all fields or types will automatically also include the new fields or types
282
+ * instructions that have excluded one or more fields or types, will NOT include the new fields or types
219
283
 
220
- ### Caption generation
221
- AI Assist can optionally generate captions for images. This has to be enabled on an image-type/field,
222
- by setting the `options.captionField` on the image type, where `captionField` is the field name of a
284
+ ## Image description generation
285
+ AI Assist can optionally generate descriptions for images. This has to be enabled on an image-type/field,
286
+ by setting the `options.aiAssist.imageDescriptionField` on the image type, where `imageDescriptionField` is the field name of a
223
287
  custom string-field on the image object:
224
288
 
225
289
  ```tsx
@@ -230,21 +294,479 @@ defineField({
230
294
  fields: [
231
295
  defineField({
232
296
  type: 'string',
233
- name: 'caption',
234
- title: 'Caption',
297
+ name: 'altText',
298
+ title: 'Alternative text',
235
299
  }),
236
300
  ],
237
301
  options: {
238
- captionField: 'caption',
302
+ aiAssist: {
303
+ imageDescriptionField: 'altText',
304
+ }
239
305
  },
240
306
  })
241
307
  ```
242
- This will add a "Generate caption" action to the configured field.
243
- "Generate caption" action will automatically run whenever the image changes.
308
+ This will add a "Generate image description" action to the configured field.
309
+ "Generate image description" action will automatically run whenever the image changes.
244
310
 
245
- `captionField` can be a nested field, if the image has object field, ie `captionField: 'wrapper.caption'`.
311
+ `imageDescriptionField` can be a nested field, if the image has object field, ie `imageDescriptionField: 'wrapper.altText'`.
246
312
  Fields within array items are not supported.
247
313
 
314
+ ## Image generation
315
+ <img width="600" alt="image" src="https://github.com/sanity-io/assist/assets/835514/c4de6791-f530-4cd1-b0c2-96ef988bc256">
316
+
317
+ AI Assist can generate assets for images configured with a prompt field.
318
+
319
+ An image is generated directly by using the "Generate image from prompt" instruction on the prompt field,
320
+ or indirectly whenever the image prompt field is written to by an AI Assist instruction.
321
+
322
+ ### Configure
323
+ To enable image generation for an image field, the image must:
324
+ - set `options.aiAssist.imageInstructionField` to a child-path relative to the image
325
+ - have a `string` or `text` field that corresponds to the `imageInstructionField` path
326
+
327
+ This will add a "Generate image from prompt" instruction to the image prompt field. Running it will generate and image.
328
+
329
+ Additionally, whenever an AI Assist instruction writes to the image prompt field, the image will be generated.
330
+
331
+ This could be a document instruction, an instruction for the image field or parent object, or directly on the image prompt field.
332
+
333
+ A common styleguide can achieved by adding an instruction to the image prompt field that rewrites whatever value is there, to include a common style.
334
+ Use AI context documents to apply a reusable styleguide to the prompt rewriting as needed.
335
+
336
+ #### Example
337
+
338
+ Given the following document schema
339
+ ```ts
340
+ defineType({
341
+ type: 'document',
342
+ name: 'article',
343
+ fields: [
344
+ defineField({
345
+ type: 'image',
346
+ name: 'articleImage',
347
+ fields: [
348
+ defineField({
349
+ type: 'text',
350
+ name: 'imagePrompt',
351
+ title: 'Image prompt',
352
+ rows: 2,
353
+ }),
354
+ ],
355
+ options: {
356
+ imagePromptField: 'imagePromptField',
357
+ },
358
+ })
359
+ ]
360
+ })
361
+ ```
362
+
363
+ To directly generate an image based on the value in the prompt field,
364
+ run the "Generate image from prompt" instruction that is automatically added.
365
+
366
+ For better image results or to ensure a consistent style, rewrite the prompt before generating the image:
367
+
368
+ ### Example prompt expansion instruction
369
+ <img width="267" alt="image" src="https://github.com/sanity-io/assist/assets/835514/dabc6910-80d3-4a69-940f-49ac5cae9ade">
370
+
371
+ For better image results, use an instruction that expands the prompt to be more detailed.
372
+
373
+ Example instruction text:
374
+
375
+ ```
376
+ Rewrite image prompts for image generation according to the following rules:
377
+ - Be Specific: Include detailed descriptions of the scene, objects, colors, and any characters. Instead of saying "a cat in a garden", say "a fluffy gray cat sitting beside pink tulips in a sunny garden".
378
+ - Set the Scene: Describe the environment or background. Mention if it's indoors or outdoors, the time of day, weather conditions, and any specific setting details like a beach, forest, cityscape, etc.
379
+ - Detail Characters: If your image includes people or animals, specify their appearance, clothing, poses, and expressions. For example, "a smiling young woman with short black hair, wearing a red dress, standing under a tree".
380
+ - Color and Style: Mention specific colors and artistic styles you prefer. For instance, "bright, vivid colors with a watercolor effect".
381
+ - Mood and Atmosphere: Describe the mood or atmosphere of the image. Words like 'peaceful', 'dynamic', 'mysterious', or 'joyful' can guide the AI in capturing the right tone.
382
+ - Avoid Ambiguity: Be clear and direct. Avoid using vague or abstract concepts that the AI might struggle to interpret.
383
+ - Follow the Guidelines: Ensure your prompt doesn't include any content against usage policies, such as depictions of real people, copyrighted characters, or sensitive subjects.
384
+
385
+ Keep it 100 words or less.
386
+
387
+ The prompt to rewrite is:
388
+ {Reference to image-prompt-field}
389
+ ```
390
+
391
+ The rules can be extracted into an AI Context document and reused in other instructions as needed. This approach can also be used to inform a reusable styleguide for image generation.
392
+ ## Full document translation
393
+ <img width="250" alt="Translate document action" src="https://github.com/sanity-io/assist/assets/835514/932968ee-1a8c-4389-8822-338188f88b40">
394
+
395
+ AI assist offers full document translations, which is ideal for pairing with [@sanity/document-internationalization](https://github.com/sanity-io/document-internationalization).
396
+
397
+ Translations are done deeply; visiting nested objects, arrays and even Portable text annotations.
398
+
399
+ ### What AI Assist full document translations solves
400
+
401
+ Given a document written in one language, AI assist can translate the document in place to a language specified by a language field in the document.
402
+
403
+ When the document translation feature is enabled, AI Assist will go through the document field by field, translating all string and portable text fields into the language specified in the document's language field.
404
+
405
+ This works well with [@sanity/document-internationalization](https://github.com/sanity-io/document-internationalization), where documents are duplicated from a source language and set a hidden language field.
406
+
407
+ AI assist allows editors to translate these documents into the desired language immediately.
408
+
409
+ ### Configure document translations
410
+
411
+ To enable full document translations, set `translate.document.languageField` to the path of the language field in your documents.
412
+
413
+ All documents with a language field will get a "Translate document" instruction added to the assist drop-down for the document.
414
+
415
+ To limit which document types get "Translate document" further, provide `translate.document.documentTypes` with an array of document type names.
416
+
417
+ If the studio is using [@sanity/document-internationalization](https://github.com/sanity-io/document-internationalization), these options should be the same as those used for that plugin.
418
+
419
+ **Example configs**
420
+
421
+ ```ts
422
+ // This will add a "Translate document" instruction to all documents with a language field
423
+ assist({
424
+ translate: {
425
+ document: {
426
+ languageField: 'language'
427
+ }
428
+ }
429
+ })
430
+ ```
431
+
432
+ ```ts
433
+ // This will add a "Translate document" instruction only to the 'article' document type
434
+ assist({
435
+ translate: {
436
+ document: {
437
+ languageField: 'language',
438
+ documentTypes: ['article']
439
+ }
440
+ }
441
+ })
442
+ ```
443
+
444
+ **All configuration params**
445
+ ```ts
446
+ assist({
447
+ translate: {
448
+ /** Config for document types with a single language field that determines the language for the whole document. */
449
+ document: {
450
+ /**
451
+ * Required config, enable document tranlations.
452
+ *
453
+ * Path to language field in documents. Can be a hidden field.
454
+ * For instance: 'config.language'
455
+ *
456
+ * For projects that use the `@sanity/document-internationalization` plugin,
457
+ * this should be the same as `languageField` config for that plugin (which defaults to 'language')
458
+ */
459
+ languageField: string,
460
+
461
+ /**
462
+ * `documentTypes` should be an array of strings where each entry must match a name from your document schemas.
463
+ *
464
+ * this property will add a translate instruction to these document types if defined.
465
+ * If undefined, the instruction will be added to all documents with aiAssistance enabled and a field matching `languageField` config.
466
+ *
467
+ * Documents with translation support will get a "Translate document>" instruction added.
468
+ **/
469
+ documentTypes: string[]
470
+ }
471
+ }
472
+ })
473
+ ```
474
+
475
+ ## Field level translations
476
+ <img width="250" alt="Translate fields action" src="https://github.com/sanity-io/assist/assets/835514/99819cd4-578e-43b2-8c70-8e39afff5f09">
477
+
478
+ <img width="250" alt="Translate fields dialog" src="https://github.com/sanity-io/assist/assets/835514/fe3d289c-49b6-46dd-ae2f-cd509a01534a">
479
+
480
+ AI assist offers field-level translations, which is ideal for using alongside with[sanity-plugin-internationalized-array](https://github.com/sanity-io/sanity-plugin-internationalized-array?tab=readme-ov-file#sanity-plugin-internationalized-array) and (@sanity/language-filter)[https://github.com/sanity-io/language-filter]
481
+
482
+ ### What AI Assist field-level translations solves
483
+
484
+ Given a document with field values in different languages, AI assist can transfer and translate from one language to the others.
485
+
486
+ The typical use case would be for documents that use internationalized wrapper types to hold values for multiple languages.
487
+
488
+ AI Assist supports complex values, so language fields that hold nested objects, portable text, or arrays will also be translated.
489
+
490
+ When initiating translations, editors select a language to translate from and which languages to translate to. This means that AI Assist supports partial translations in cases where editors are responsible for only some languages in the document.
491
+
492
+ ### Configure field translations
493
+ To enable field-level translations, set `translate.field.documentTypes` to an array with which document types should get field translations, and `translate.field.languages`
494
+
495
+ ```ts
496
+ assist({
497
+ translate: {
498
+ field: {
499
+ documentTypes: ['article'],
500
+ languages: [
501
+ {id: 'en', title: 'English'},
502
+ {id: 'de', title: 'German'}
503
+ ]
504
+ },
505
+ },
506
+ })
507
+ ```
508
+
509
+ These documents will get a "Translate fields" instruction added to the document AI Assist dropdown.
510
+
511
+ Out of the box, this is sufficient config for document types using `internationalizedArray*` types for localization [sanity-plugin-internationalized-array](https://github.com/sanity-io/sanity-plugin-internationalized-array?tab=readme-ov-file#sanity-plugin-internationalized-array).
512
+
513
+ It will also work without further config for object types named "locale*", with one field per language:
514
+
515
+ *Example locale object supported by default*
516
+
517
+ ```ts
518
+ // Object type with name starting with 'locale', and one field per language language
519
+ defineType({
520
+ type: 'object',
521
+ name: 'localeString',
522
+ fields: [
523
+ defineField({
524
+ // these do not have to be string, could be any type
525
+ type: 'string',
526
+ name: 'en',
527
+ title: 'English'
528
+ }),
529
+ defineField({
530
+ type: 'string',
531
+ name: 'de',
532
+ title: 'German'
533
+ })
534
+ ]
535
+ })
536
+ ```
537
+
538
+ **If your schema is not using either of these structures**, confer [Custom language fields](#custom-language-fields).
539
+
540
+ ### Loading field languages
541
+ Languages must be an array of objects with an id and title.
542
+
543
+ ```ts
544
+ assist({
545
+ translate: {
546
+ field: {
547
+ languages: [
548
+ {id: 'en', title: 'English'},
549
+ {id: 'de', title: 'German'}
550
+ ]
551
+ },
552
+ },
553
+ })
554
+ ```
555
+
556
+ Or an asynchronous function that returns an array of objects with an id and title.
557
+
558
+ ```ts
559
+ assist({
560
+ translate: {
561
+ field: {
562
+ languages: async () => {
563
+ const response = await fetch('https://example.com/languages')
564
+ return response.json()
565
+ }
566
+ },
567
+ },
568
+ })
569
+ ```
570
+
571
+ The async function contains a configured Sanity Client in the first parameter, allowing you to store Language options as documents. Your query should return an array of objects with an id and title.
572
+
573
+
574
+ ```ts
575
+ assist({
576
+ translate: {
577
+ field: {
578
+ languages: async () => {
579
+ const response = await client.fetch(`*[_type == "language"]{ id, title }`)
580
+ return response
581
+ }
582
+ },
583
+ },
584
+ })
585
+ ```
586
+
587
+ Additionally, you can "pick" fields from a document, to pass into the query. For example, if you have a concept of "Markets" where only certain language fields are required in certain markets.
588
+
589
+ In this example, each language document has an array of strings called markets to declare where that language can be used. And the document being authored has a single market field.
590
+
591
+ ```ts
592
+ assist({
593
+ translate: {
594
+ field: {
595
+ selectLanguageParams: {
596
+ market: 'market'
597
+ },
598
+ languages: async (client, {market = ``}) => {
599
+ const response = await client.fetch(
600
+ `*[_type == "language" && $market in markets]{ id, title }`,
601
+ {market}
602
+ )
603
+ return response
604
+ },
605
+ },
606
+ },
607
+ })
608
+ ```
609
+
610
+ ### Custom language fields
611
+ By providing a function to `translate.field.translationOutputs`, complete control over which fields belong to which language is given.
612
+
613
+ `translationOutputs` is used when an editor uses the "Translate fields" instruction.
614
+
615
+ It determines the relationships between document paths: Given a document path and a language, it should return into which sibling paths translations are output.
616
+
617
+ `translationOutputs` is invoked once per path in the document (limited to a depth of 6), with the following:
618
+
619
+ * `documentMember` - the field or array item for a given path; contains the path and its schemaType,
620
+ * `enclosingType` - the schema type of the parent holding the member
621
+ * `translateFromLanguageId` - the languageId for the language the users want to to translate from
622
+ * `translateToLanguageIds` - all languageIds the user can translate to
623
+
624
+ The function should return a `TranslationOutput[]` array that contains all the paths where translations from `documentMember` (in the language given by translateFromLanguageId) should be output.
625
+
626
+ The function should return `undefined` for all documentMembers that should not be directly translated, or are nested fields under a translated path.
627
+
628
+ #### Default function
629
+
630
+ The default `translationOutputs` is available using `import {defaultTranslationOutputs} from '@sanity/assist`.
631
+
632
+ #### Example
633
+
634
+ Given the following document:
635
+
636
+ ```ts
637
+ {
638
+ titles: {
639
+ _type: 'languageObject',
640
+ en: {
641
+ _type: 'titleObject',
642
+ title: 'Some title',
643
+ subtitle: 'Some subtitle'
644
+ },
645
+ de: {
646
+ _type: 'titleObject',
647
+ }
648
+ }
649
+ }
650
+ ```
651
+
652
+ When translating from English to German, `translationOutputs` will be
653
+ invoked multiple times.
654
+
655
+ The following parameters will be the same every invocation:
656
+
657
+ * `translateFromLanguageId` will be `'en'`
658
+ * `translateToLanguageIds` will be `['de']`
659
+
660
+ `documentMember` and `enclosingType` will change between each invocation, and take the following values:
661
+
662
+ 1. `{path: 'titles', name: 'titles', schemaType: ObjectSchemaType}`, `ObjectSchemaType`
663
+ 2. `{path: 'titles.en', name: 'en', schemaType: ObjectSchemaType}`, `ObjectSchemaType`
664
+ 3. `{path: 'titles.en.title', name: 'title', schemaType: StringSchemaType}`, `ObjectSchemaType`
665
+ 4. `{path: 'titles.en.subtitle', name: 'subtitle', schemaType: StringSchemaType}`, `ObjectSchemaType`
666
+ 5. `{path: 'titles.de', name: 'de', schemaType: ObjectSchemaType}`, `ObjectSchemaType`
667
+
668
+ To indicate that you want everything under `title.en` to be translated into `title.de`, `translationOutputs` needs to return [id: 'de', outputPath: 'titles.de'] when invoked with `documentMember.path: 'titles.en'`.
669
+
670
+ The following function enables this:
671
+
672
+ ```ts
673
+ function translationOutputs(member, enclosingType, translateFromLanguageId, translateToLanguageIds) {
674
+ const parentIsLanguageWrapper = enclosingType.jsonType === 'object' && enclosingType.name.startsWith('language')
675
+
676
+ if (parentIsLanguageWrapper && translateFromLanguageId === member.name) {
677
+
678
+ // [id: 'de', ]
679
+ return translateToLanguageIds.map((translateToId) => ({
680
+ id: translateToId,
681
+ // in this example, member.path is 'titles.en'
682
+ // so this changes titles.en -> titles.de
683
+ outputPath: [...member.path.slice(0, -1), translateToId],
684
+ }))
685
+ }
686
+
687
+ // ignore other members
688
+ return undefined
689
+ }
690
+ ```
691
+
692
+ ### Full field translation configuration example
693
+
694
+ ```ts
695
+ assist({
696
+ translate: {
697
+ field: {
698
+ documentTypes: ['article'],
699
+ selectLanguageParams: {market: 'market'},
700
+ apiVersion: '2023-01-01',
701
+ languages: (client, {market}) => {
702
+ return client.fetch(
703
+ `*[_type == "language" && $market in markets]{ id, title }`,
704
+ {market}
705
+ )
706
+ },
707
+ translationOutputs: (member, enclosingType, fromLanguageId, toLanguageIds) => {
708
+ // When the document member is named the same as fromLangagueId
709
+ // and it is a field in a object with a name starting with "language"
710
+ // then we return the paths to all other sibling language fields (and their langauge id)
711
+ // It is ok that the member is an object, then all child fields will be translated
712
+ if (translateFromLanguageId === member.name && enclosingType.jsonType === 'object' && enclosingType.name.startsWith('locale')) {
713
+ return translateToLanguageIds.map((translateToId) => ({
714
+ id: translateToId,
715
+ //changes path.to.en -> path.to.de (for instance)
716
+ outputPath: [...member.path.slice(0, -1), translateToId],
717
+ }))
718
+ }
719
+ // all other member paths are skipped
720
+ return undefined
721
+ }
722
+ },
723
+ },
724
+ })
725
+ ```
726
+
727
+ ## Adding translation actions to fields
728
+
729
+ <img width="250" alt="Translate action on field" src="https://github.com/sanity-io/assist/assets/835514/e6dc0860-90a7-4f7a-b3d2-71893b09862f">
730
+
731
+ <img width="250" alt="Translate fields action on field" src="https://github.com/sanity-io/assist/assets/835514/acc5fa23-2022-4eae-922d-5c83dda7379c">
732
+
733
+ By default, “Translate document” and “Translate fields…” instructions are only added to the document instruction dropdown.
734
+
735
+ These instructions can also be added to fields by setting
736
+ `options.aiAssist.translateAction: true` for a field or type.
737
+
738
+ This allows editors to translate only parts of the document, and can be useful to enable on `internatinalizedArrays` or `locale` wrapper object types.
739
+
740
+ For document types configured for full document translations, a "Translate" action will be added. Running it will translate the field to the language set in the language field
741
+
742
+ For document types configured for field translations, a "Translate fields..." action will be added. Running it will open a dialog with language selectors.
743
+
744
+
745
+ #### Example
746
+
747
+ ```ts
748
+ defineField({
749
+ name: 'subtitle',
750
+ type: 'internationalizedArrayString',
751
+ title: 'Subtitle',
752
+ options: {
753
+ aiAssist: {
754
+ translateAction: true
755
+ }
756
+ },
757
+ })
758
+ ```
759
+
760
+ ## Caveats
761
+
762
+ Large Language Models (LLMs) are a new technology. Constraints and limitations are still being explored,
763
+ but some common caveats to the field that you may run into using AI Assist are:
764
+
765
+ * Limits to instruction length: Long instructions on deep content structures may exhaust model context
766
+ * Timeouts: To be able to write structured content, we're using the largest language models - long-running results may time out or intermittently fail
767
+ * Limited capacity: The underlying LLM APIs used by AI Assist are resource constrained
768
+
769
+
248
770
  ## Third party sub-processors
249
771
 
250
772
  This version of the feature uses OpenAI.com as a third-party sub-processor. Their security posture has been vetted by Sanity's security team, and approved for use.
@@ -3,4 +3,5 @@ import cjs from './index.js';
3
3
  export const SchemaTypeTool = cjs.SchemaTypeTool;
4
4
  export const assist = cjs.assist;
5
5
  export const contextDocumentTypeName = cjs.contextDocumentTypeName;
6
+ export const defaultLanguageOutputs = cjs.defaultLanguageOutputs;
6
7