@sanity/assist 5.0.4 → 6.0.1

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 (131) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +28 -254
  3. package/dist/index.d.ts +322 -410
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +3205 -2670
  6. package/dist/index.js.map +1 -1
  7. package/package.json +41 -81
  8. package/dist/index.cjs +0 -4239
  9. package/dist/index.cjs.map +0 -1
  10. package/dist/index.d.cts +0 -791
  11. package/sanity.json +0 -8
  12. package/src/_lib/connector/ConnectFromRegion.tsx +0 -25
  13. package/src/_lib/connector/ConnectToRegion.tsx +0 -23
  14. package/src/_lib/connector/ConnectorRegion.tsx +0 -24
  15. package/src/_lib/connector/ConnectorsProvider.tsx +0 -20
  16. package/src/_lib/connector/ConnectorsStore.ts +0 -122
  17. package/src/_lib/connector/ConnectorsStoreContext.ts +0 -5
  18. package/src/_lib/connector/helpers.ts +0 -5
  19. package/src/_lib/connector/index.ts +0 -9
  20. package/src/_lib/connector/mapConnectorToLine.ts +0 -83
  21. package/src/_lib/connector/types.ts +0 -56
  22. package/src/_lib/connector/useConnectorsStore.ts +0 -14
  23. package/src/_lib/connector/useRegionRects.ts +0 -142
  24. package/src/_lib/fixedListenQuery.ts +0 -101
  25. package/src/_lib/form/DocumentForm.tsx +0 -201
  26. package/src/_lib/form/constants.ts +0 -1
  27. package/src/_lib/form/helpers.ts +0 -32
  28. package/src/_lib/form/index.ts +0 -1
  29. package/src/_lib/randomKey.ts +0 -29
  30. package/src/_lib/useListeningQuery.ts +0 -62
  31. package/src/_lib/usePrevious.ts +0 -9
  32. package/src/assistConnectors/AssistConnectorsOverlay.tsx +0 -133
  33. package/src/assistConnectors/ConnectorPath.tsx +0 -63
  34. package/src/assistConnectors/draw/arrowPath.ts +0 -9
  35. package/src/assistConnectors/draw/connectorPath.ts +0 -142
  36. package/src/assistConnectors/index.ts +0 -1
  37. package/src/assistDocument/AssistDocumentContext.tsx +0 -51
  38. package/src/assistDocument/AssistDocumentContextProvider.tsx +0 -17
  39. package/src/assistDocument/AssistDocumentInput.tsx +0 -61
  40. package/src/assistDocument/AssistDocumentLayout.tsx +0 -12
  41. package/src/assistDocument/RequestRunInstructionProvider.tsx +0 -61
  42. package/src/assistDocument/components/AssistDocumentForm.tsx +0 -287
  43. package/src/assistDocument/components/AssistTypeContext.tsx +0 -7
  44. package/src/assistDocument/components/FieldRefPreview.tsx +0 -26
  45. package/src/assistDocument/components/InstructionsArrayField.tsx +0 -8
  46. package/src/assistDocument/components/InstructionsArrayInput.tsx +0 -27
  47. package/src/assistDocument/components/SelectedFieldContext.tsx +0 -10
  48. package/src/assistDocument/components/generic/HiddenFieldTitle.tsx +0 -5
  49. package/src/assistDocument/components/helpers.ts +0 -21
  50. package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +0 -32
  51. package/src/assistDocument/components/instruction/FieldRefInput.tsx +0 -54
  52. package/src/assistDocument/components/instruction/InstructionInput.tsx +0 -89
  53. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +0 -46
  54. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +0 -206
  55. package/src/assistDocument/components/instruction/PromptInput.tsx +0 -59
  56. package/src/assistDocument/components/instruction/appearance/IconInput.tsx +0 -46
  57. package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +0 -37
  58. package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +0 -127
  59. package/src/assistDocument/hooks/useDocumentState.ts +0 -6
  60. package/src/assistDocument/hooks/useInstructionToaster.tsx +0 -75
  61. package/src/assistDocument/hooks/useStudioAssistDocument.ts +0 -99
  62. package/src/assistDocument/index.ts +0 -1
  63. package/src/assistFormComponents/AssistField.tsx +0 -63
  64. package/src/assistFormComponents/AssistFormBlock.tsx +0 -31
  65. package/src/assistFormComponents/AssistInlineFormBlock.tsx +0 -13
  66. package/src/assistFormComponents/AssistItem.tsx +0 -21
  67. package/src/assistFormComponents/validation/listItem.tsx +0 -63
  68. package/src/assistFormComponents/validation/validationList.tsx +0 -90
  69. package/src/assistInspector/AssistInspector.tsx +0 -419
  70. package/src/assistInspector/FieldAutocomplete.tsx +0 -146
  71. package/src/assistInspector/InstructionTaskHistoryButton.tsx +0 -262
  72. package/src/assistInspector/constants.ts +0 -1
  73. package/src/assistInspector/helpers.ts +0 -211
  74. package/src/assistInspector/index.ts +0 -27
  75. package/src/assistLayout/AiAssistanceConfigContext.tsx +0 -32
  76. package/src/assistLayout/AiAssistanceConfigProvider.tsx +0 -98
  77. package/src/assistLayout/AssistLayout.tsx +0 -39
  78. package/src/assistLayout/RunInstructionProvider.tsx +0 -278
  79. package/src/assistLayout/fieldRefCache.tsx +0 -34
  80. package/src/assistTypes.ts +0 -83
  81. package/src/components/AssistFeatureBadge.tsx +0 -9
  82. package/src/components/FadeInContent.tsx +0 -40
  83. package/src/components/HideReferenceChangedBannerInput.tsx +0 -25
  84. package/src/components/ImageContext.tsx +0 -85
  85. package/src/components/SafeValueInput.tsx +0 -74
  86. package/src/components/TimeAgo.tsx +0 -18
  87. package/src/constants.ts +0 -20
  88. package/src/fieldActions/PrivateIcon.tsx +0 -20
  89. package/src/fieldActions/assistFieldActions.tsx +0 -320
  90. package/src/fieldActions/customFieldActions.tsx +0 -333
  91. package/src/fieldActions/generateCaptionActions.tsx +0 -77
  92. package/src/fieldActions/generateImageActions.tsx +0 -58
  93. package/src/fieldActions/useUserInput.ts +0 -107
  94. package/src/globals.d.ts +0 -4
  95. package/src/helpers/assistSupported.ts +0 -49
  96. package/src/helpers/conditionalMembers.test.ts +0 -319
  97. package/src/helpers/conditionalMembers.ts +0 -134
  98. package/src/helpers/ids.test.ts +0 -28
  99. package/src/helpers/ids.ts +0 -23
  100. package/src/helpers/misc.ts +0 -25
  101. package/src/helpers/styleguide.ts +0 -24
  102. package/src/helpers/typeUtils.ts +0 -60
  103. package/src/helpers/useAssistSupported.ts +0 -8
  104. package/src/index.ts +0 -26
  105. package/src/onboarding/FirstAssistedPathProvider.tsx +0 -30
  106. package/src/onboarding/InspectorOnboarding.tsx +0 -47
  107. package/src/onboarding/onboardingStore.ts +0 -32
  108. package/src/plugin.tsx +0 -162
  109. package/src/presence/AiFieldPresence.tsx +0 -28
  110. package/src/presence/AssistAvatar.tsx +0 -96
  111. package/src/presence/AssistDocumentPresence.tsx +0 -50
  112. package/src/presence/useAssistPresence.ts +0 -64
  113. package/src/schemas/assistDocumentSchema.tsx +0 -497
  114. package/src/schemas/contextDocumentSchema.tsx +0 -57
  115. package/src/schemas/index.ts +0 -69
  116. package/src/schemas/serialize/SchemTypeTool.tsx +0 -103
  117. package/src/schemas/serialize/schemaUtils.ts +0 -38
  118. package/src/schemas/serialize/serializeSchema.test.ts +0 -819
  119. package/src/schemas/serialize/serializeSchema.ts +0 -224
  120. package/src/schemas/serializedSchemaTypeSchema.ts +0 -60
  121. package/src/schemas/typeDefExtensions.ts +0 -127
  122. package/src/translate/FieldTranslationProvider.tsx +0 -382
  123. package/src/translate/getLanguageParams.ts +0 -26
  124. package/src/translate/languageStore.ts +0 -18
  125. package/src/translate/paths.test.ts +0 -181
  126. package/src/translate/paths.ts +0 -183
  127. package/src/translate/translateActions.tsx +0 -205
  128. package/src/translate/types.ts +0 -197
  129. package/src/types.ts +0 -220
  130. package/src/useApiClient.ts +0 -338
  131. package/v2-incompatible.js +0 -11
package/src/types.ts DELETED
@@ -1,220 +0,0 @@
1
- import {PortableTextBlock, PortableTextMarkDefinition, PortableTextSpan} from '@portabletext/types'
2
- import {SanityDocument} from 'sanity'
3
-
4
- //id prefixes
5
- export const assistDocumentIdPrefix = 'sanity.assist.schemaType.'
6
- export const assistDocumentStatusIdPrefix = 'sanity.assist.status.'
7
- export const assistSchemaIdPrefix = 'sanity.assist.schema.'
8
-
9
- // type names
10
- export const assistDocumentTypeName = 'sanity.assist.schemaType.annotations' as const
11
- export const assistFieldTypeName = 'sanity.assist.schemaType.field' as const
12
- export const instructionTypeName = 'sanity.assist.instruction' as const
13
- export const promptTypeName = 'sanity.assist.instruction.prompt' as const
14
-
15
- export const userInputTypeName = 'sanity.assist.instruction.userInput' as const
16
- export const instructionContextTypeName = 'sanity.assist.instruction.context' as const
17
- export const fieldReferenceTypeName = 'sanity.assist.instruction.fieldRef' as const
18
-
19
- // user-facing type. Intentionally does not have sanity. prefix
20
- export const contextDocumentTypeName = 'assist.instruction.context' as const
21
-
22
- export const assistTasksStatusTypeName = 'sanity.assist.task.status' as const
23
- export const instructionTaskTypeName = 'sanity.assist.instructionTask' as const
24
- export const fieldPresenceTypeName = 'sanity.assist.instructionTask.presence' as const
25
-
26
- export const assistSerializedTypeName = 'sanity.assist.serialized.type' as const
27
- export const assistSerializedFieldTypeName = 'sanity.assist.serialized.field' as const
28
-
29
- export const outputFieldTypeName = 'sanity.assist.output.field' as const
30
- export const outputTypeTypeName = 'sanity.assist.output.type' as const
31
-
32
- //url params
33
- export const inspectParam = 'inspect' as const
34
- export const fieldPathParam = 'pathKey' as const
35
- export const instructionParam = 'instruction' as const
36
-
37
- // other constants
38
- export const documentRootKey = '<document>'
39
-
40
- export type SerializedSchemaMember = Omit<SerializedSchemaType, 'name' | '_type'> & {
41
- _type?: typeof assistSerializedFieldTypeName
42
- name?: string
43
- }
44
-
45
- export interface SerializedSchemaType {
46
- _type?: typeof assistSerializedTypeName
47
- _id?: string
48
- type: string
49
- name: string
50
- title?: string
51
- fields?: SerializedSchemaMember[]
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'
59
- options?: {
60
- /** equivalent to options.aiAssist.imageDescriptionField - not renamed in the api for backwards compatability */
61
- imagePromptField?: string
62
- embeddingsIndex?: string
63
- }
64
- }
65
-
66
- export interface AssistDocument extends SanityDocument {
67
- fields?: AssistField[]
68
- instructions?: StudioInstruction[]
69
- }
70
-
71
- export interface PresetInstruction {
72
- _key: string
73
- prompt?: PromptTextBlock[]
74
-
75
- title?: string
76
- /**
77
- * String key from `@sanity/icons` IconMap
78
- */
79
- icon?: string
80
-
81
- /**
82
- * Type/field filter
83
- */
84
- output?: (OutputFieldItem | OutputTypeItem)[]
85
- }
86
-
87
- export interface PresetField {
88
- path?: string
89
- instructions?: PresetInstruction[]
90
- }
91
-
92
- export interface AssistPreset {
93
- fields?: PresetField[]
94
- }
95
-
96
- export interface SanityAssistDocument {
97
- _id: string
98
- _type: typeof assistDocumentTypeName
99
- fields?: StudioAssistField[]
100
- }
101
-
102
- export interface StudioAssistDocument extends SanityAssistDocument {
103
- // added after loading
104
- tasks?: InstructionTask[]
105
- }
106
-
107
- export interface AssistField {
108
- _key: string
109
- _type: typeof assistFieldTypeName
110
- path?: string
111
- instructions?: StudioInstruction[]
112
- }
113
-
114
- export interface StudioAssistField {
115
- _key: string
116
- path?: string
117
- instructions?: StudioInstruction[]
118
-
119
- // added
120
- tasks?: InstructionTask[]
121
- }
122
-
123
- export interface FieldRef extends PortableTextMarkDefinition {
124
- _type: typeof fieldReferenceTypeName
125
- path?: string
126
- }
127
-
128
- export interface ContextBlock {
129
- _type: typeof instructionContextTypeName
130
- reference?: {
131
- _type: 'reference'
132
- _ref?: string
133
- }
134
- }
135
-
136
- export interface UserInputBlock {
137
- _type: typeof userInputTypeName
138
- _key: string
139
- message?: string
140
- description?: string
141
- }
142
-
143
- export type InlinePromptBlock = PortableTextSpan | FieldRef | UserInputBlock | ContextBlock
144
- export type PromptTextBlock = Omit<
145
- PortableTextBlock<never, InlinePromptBlock, 'normal', never>,
146
- '_type'
147
- > & {_type: 'block'}
148
-
149
- export type PromptBlock = PromptTextBlock | FieldRef | ContextBlock | UserInputBlock
150
-
151
- export interface AiPresence {
152
- _key: string
153
- _type: typeof fieldPresenceTypeName
154
- path?: string
155
- started?: string
156
- }
157
-
158
- export type TaskEndedReason = 'success' | 'error' | 'aborted' | 'timeout'
159
-
160
- export interface InstructionTask {
161
- _key: string
162
- _type: typeof instructionTaskTypeName
163
- instructionKey?: string
164
- title?: string
165
- path?: string
166
- started?: string
167
- updated?: string
168
- ended?: string
169
- message?: string
170
- reason?: TaskEndedReason
171
- presence?: AiPresence[]
172
- startedByUserId?: string
173
-
174
- //added by studio
175
- // eslint-disable-next-line no-use-before-define
176
- instruction?: StudioInstruction
177
- }
178
-
179
- export interface StudioInstruction {
180
- _key: string
181
- _type: typeof instructionTypeName
182
- prompt?: PromptBlock[]
183
-
184
- icon?: string
185
- userId?: string
186
- title?: string
187
- placeholder?: string
188
- output?: (OutputFieldItem | OutputTypeItem)[]
189
-
190
- //added after query / synthetic fields
191
- tasks?: InstructionTask[]
192
- }
193
-
194
- export interface AssistTasksStatus {
195
- _id: string
196
- _type: typeof assistTasksStatusTypeName
197
- tasks?: InstructionTask[]
198
- }
199
-
200
- export interface AssistInspectorRouteParams {
201
- [inspectParam]?: string
202
- [fieldPathParam]?: string
203
- [instructionParam]?: string
204
- }
205
-
206
- export interface OutputFieldItem {
207
- _type: typeof outputFieldTypeName
208
- _key: string
209
- //path relative to the field the instruction is for (same as _key)
210
- relativePath?: string
211
- }
212
-
213
- export interface OutputTypeItem {
214
- _type: typeof outputTypeTypeName
215
- _key: string
216
- /* array item type name */
217
- type?: string
218
- //path relative to the array-field the instruction is for, can be empty string (the array itself, same as _key)
219
- relativePath?: string
220
- }
@@ -1,338 +0,0 @@
1
- import type {SanityClient} from '@sanity/client'
2
- import {useToast} from '@sanity/ui'
3
- import {useCallback, useMemo, useState} from 'react'
4
- import {Path, pathToString, useClient, useCurrentUser} from 'sanity'
5
-
6
- import {useAiAssistanceConfig, useSerializedTypes} from './assistLayout/AiAssistanceConfigContext'
7
- import {ConditionalMemberState} from './helpers/conditionalMembers'
8
- import {FieldLanguageMap} from './translate/paths'
9
- import {documentRootKey} from './types'
10
-
11
- export interface UserTextInstance {
12
- blockKey: string
13
- userInput: string
14
- }
15
-
16
- export interface RunInstructionRequest {
17
- documentId: string
18
- assistDocumentId: string
19
- path: string
20
- typePath?: string
21
- instructionKey: string
22
- userId?: string
23
- userTexts?: UserTextInstance[]
24
- conditionalMembers?: ConditionalMemberState[]
25
- }
26
-
27
- export interface InstructStatus {
28
- enabled: boolean
29
- initialized: boolean
30
- validToken: boolean
31
- }
32
-
33
- export interface TranslateRequest {
34
- documentId: string
35
- translatePath: Path
36
- languagePath?: string
37
- styleguide: () => Promise<string | undefined>
38
- fieldLanguageMap?: FieldLanguageMap[]
39
- conditionalMembers?: ConditionalMemberState[]
40
- }
41
-
42
- const basePath = '/assist/tasks/instruction'
43
- export const API_VERSION_WITH_EXTENDED_TYPES = '2025-04-01'
44
-
45
- export function canUseAssist(status: InstructStatus | undefined) {
46
- return status?.enabled && status.initialized && status.validToken
47
- }
48
-
49
- export function useApiClient(customApiClient?: (defaultClient: SanityClient) => SanityClient) {
50
- const client = useClient({apiVersion: API_VERSION_WITH_EXTENDED_TYPES})
51
- return useMemo(
52
- () => (customApiClient ? customApiClient(client) : client),
53
- [client, customApiClient],
54
- )
55
- }
56
-
57
- export function useTranslate(apiClient: SanityClient) {
58
- const [loading, setLoading] = useState(false)
59
- const user = useCurrentUser()
60
- const types = useSerializedTypes()
61
- const toast = useToast()
62
-
63
- const translate = useCallback(
64
- ({
65
- documentId,
66
- languagePath,
67
- styleguide,
68
- translatePath,
69
- fieldLanguageMap,
70
- conditionalMembers,
71
- }: TranslateRequest) => {
72
- setLoading(true)
73
-
74
- async function run() {
75
- return apiClient.request({
76
- method: 'POST',
77
- url: `/assist/tasks/translate/${apiClient.config().dataset}?projectId=${
78
- apiClient.config().projectId
79
- }`,
80
- body: {
81
- documentId,
82
- types,
83
- languagePath,
84
- userStyleguide: await styleguide(),
85
- fieldLanguageMap,
86
- conditionalMembers,
87
- translatePath:
88
- translatePath.length === 0 ? documentRootKey : pathToString(translatePath),
89
- userId: user?.id,
90
- },
91
- })
92
- }
93
-
94
- return run()
95
- .catch((e) => {
96
- toast.push({
97
- status: 'error',
98
- title: 'Translate failed',
99
- description: e.message,
100
- })
101
- setLoading(false)
102
- throw e
103
- })
104
- .finally(() => {
105
- // adding some artificial delay here
106
- // server responds with 201 then proceeds; we dont need to allow spamming the button
107
- setTimeout(() => {
108
- setLoading(false)
109
- }, 2000)
110
- })
111
- },
112
- [setLoading, apiClient, toast, user, types],
113
- )
114
-
115
- return useMemo(
116
- () => ({
117
- translate,
118
- loading,
119
- }),
120
- [translate, loading],
121
- )
122
- }
123
-
124
- export function useGenerateCaption(apiClient: SanityClient) {
125
- const [loading, setLoading] = useState(false)
126
- const user = useCurrentUser()
127
- const types = useSerializedTypes()
128
- const toast = useToast()
129
-
130
- const generateCaption = useCallback(
131
- ({path, documentId}: {path: string; documentId: string}) => {
132
- setLoading(true)
133
-
134
- return apiClient
135
- .request({
136
- method: 'POST',
137
- url: `/assist/tasks/generate-caption/${apiClient.config().dataset}?projectId=${
138
- apiClient.config().projectId
139
- }`,
140
- body: {
141
- path,
142
- documentId,
143
- types,
144
- userId: user?.id,
145
- },
146
- })
147
- .catch((e) => {
148
- toast.push({
149
- status: 'error',
150
- title: 'Generate image description failed',
151
- description: e.message,
152
- })
153
- setLoading(false)
154
- throw e
155
- })
156
- .finally(() => {
157
- // adding some artificial delay here
158
- // server responds with 201 then proceeds; we dont need to allow spamming the button
159
- setTimeout(() => {
160
- setLoading(false)
161
- }, 2000)
162
- })
163
- },
164
- [setLoading, apiClient, toast, user, types],
165
- )
166
-
167
- return useMemo(
168
- () => ({
169
- generateCaption,
170
- loading,
171
- }),
172
- [generateCaption, loading],
173
- )
174
- }
175
-
176
- export function useGenerateImage(apiClient: SanityClient) {
177
- const [loading, setLoading] = useState(false)
178
- const user = useCurrentUser()
179
- const types = useSerializedTypes()
180
- const toast = useToast()
181
-
182
- const generateImage = useCallback(
183
- ({path, documentId}: {path: string; documentId: string}) => {
184
- setLoading(true)
185
-
186
- return apiClient
187
- .request({
188
- method: 'POST',
189
- url: `/assist/tasks/generate-image/${apiClient.config().dataset}?projectId=${
190
- apiClient.config().projectId
191
- }`,
192
- body: {
193
- path,
194
- documentId,
195
- types,
196
- userId: user?.id,
197
- },
198
- })
199
- .catch((e) => {
200
- toast.push({
201
- status: 'error',
202
- title: 'Generate image from prompt failed',
203
- description: e.message,
204
- })
205
- setLoading(false)
206
- throw e
207
- })
208
- .finally(() => {
209
- // adding some artificial delay here
210
- // server responds with 201 then proceeds; we dont need to allow spamming the button
211
- setTimeout(() => {
212
- setLoading(false)
213
- }, 2000)
214
- })
215
- },
216
- [setLoading, apiClient, toast, user, types],
217
- )
218
-
219
- return useMemo(
220
- () => ({
221
- generateImage,
222
- loading,
223
- }),
224
- [generateImage, loading],
225
- )
226
- }
227
-
228
- export function useGetInstructStatus(apiClient: SanityClient) {
229
- const [loading, setLoading] = useState(true)
230
-
231
- const getInstructStatus = useCallback(async () => {
232
- setLoading(true)
233
-
234
- const projectId = apiClient.config().projectId
235
- try {
236
- const status = await apiClient.request<InstructStatus>({
237
- method: 'GET',
238
- url: `${basePath}/${apiClient.config().dataset}/status?projectId=${projectId}`,
239
- })
240
-
241
- return status
242
- } finally {
243
- setLoading(false)
244
- }
245
- }, [setLoading, apiClient])
246
-
247
- return {
248
- loading,
249
- getInstructStatus,
250
- }
251
- }
252
-
253
- export function useInitInstruct(apiClient: SanityClient) {
254
- const [loading, setLoading] = useState(false)
255
- const initInstruct = useCallback(() => {
256
- setLoading(true)
257
- return apiClient
258
- .request({
259
- method: 'GET',
260
- url: `${basePath}/${apiClient.config().dataset}/init?projectId=${
261
- apiClient.config().projectId
262
- }`,
263
- })
264
- .finally(() => {
265
- setLoading(false)
266
- })
267
- }, [setLoading, apiClient])
268
-
269
- return {
270
- loading,
271
- initInstruct,
272
- }
273
- }
274
-
275
- export function useRunInstructionApi(apiClient: SanityClient) {
276
- const toast = useToast()
277
- const [loading, setLoading] = useState(false)
278
- const user = useCurrentUser()
279
- const types = useSerializedTypes()
280
-
281
- const {
282
- config: {assist: assistConfig},
283
- } = useAiAssistanceConfig()
284
-
285
- const runInstruction = useCallback(
286
- (request: RunInstructionRequest) => {
287
- if (!user) {
288
- toast.push({
289
- status: 'error',
290
- title: 'Unable to get user for instruction.',
291
- })
292
- return undefined
293
- }
294
- setLoading(true)
295
-
296
- const {timeZone, locale} = Intl.DateTimeFormat().resolvedOptions()
297
- const defaultLocaleSettings = {timeZone, locale}
298
- const localeSettings =
299
- assistConfig?.localeSettings?.({user, defaultSettings: defaultLocaleSettings}) ??
300
- defaultLocaleSettings
301
-
302
- return apiClient
303
- .request({
304
- method: 'POST',
305
- url: `${basePath}/${apiClient.config().dataset}?projectId=${
306
- apiClient.config().projectId
307
- }`,
308
- body: {
309
- ...request,
310
- types,
311
- userId: user?.id,
312
- localeSettings,
313
- maxPathDepth: assistConfig?.maxPathDepth,
314
- },
315
- })
316
- .catch((e) => {
317
- toast.push({
318
- status: 'error',
319
- title: 'Instruction failed',
320
- description: e.message,
321
- })
322
- throw e
323
- })
324
- .finally(() => {
325
- setLoading(false)
326
- })
327
- },
328
- [apiClient, types, user, toast, assistConfig],
329
- )
330
-
331
- return useMemo(
332
- () => ({
333
- runInstruction,
334
- loading,
335
- }),
336
- [runInstruction, loading],
337
- )
338
- }
@@ -1,11 +0,0 @@
1
- const {showIncompatiblePluginDialog} = require('@sanity/incompatible-plugin')
2
- const {name, version, sanityExchangeUrl} = require('./package.json')
3
-
4
- export default showIncompatiblePluginDialog({
5
- name: name,
6
- versions: {
7
- v3: version,
8
- v2: undefined,
9
- },
10
- sanityExchangeUrl,
11
- })