@sanity/assist 2.0.4-canary.0 → 2.0.5

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 (91) hide show
  1. package/README.md +233 -214
  2. package/dist/index.esm.js +1769 -1769
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +1767 -1767
  5. package/dist/index.js.map +1 -1
  6. package/package.json +17 -18
  7. package/src/_lib/connector/ConnectFromRegion.tsx +4 -3
  8. package/src/_lib/connector/ConnectToRegion.tsx +1 -0
  9. package/src/_lib/connector/ConnectorRegion.tsx +2 -1
  10. package/src/_lib/connector/ConnectorsProvider.tsx +2 -1
  11. package/src/_lib/connector/ConnectorsStoreContext.ts +1 -0
  12. package/src/_lib/connector/index.ts +1 -1
  13. package/src/_lib/connector/mapConnectorToLine.ts +2 -2
  14. package/src/_lib/connector/useConnectorsStore.ts +2 -1
  15. package/src/_lib/connector/useRegionRects.ts +4 -3
  16. package/src/_lib/fixedListenQuery.ts +11 -11
  17. package/src/_lib/form/DocumentForm.tsx +4 -3
  18. package/src/_lib/form/helpers.ts +2 -1
  19. package/src/_lib/useListeningQuery.ts +4 -3
  20. package/src/assistConnectors/AssistConnectorsOverlay.tsx +1 -0
  21. package/src/assistConnectors/ConnectorPath.tsx +3 -2
  22. package/src/assistConnectors/draw/connectorPath.ts +13 -13
  23. package/src/assistDocument/AssistDocumentContext.tsx +3 -2
  24. package/src/assistDocument/AssistDocumentContextProvider.tsx +2 -1
  25. package/src/assistDocument/AssistDocumentInput.tsx +9 -8
  26. package/src/assistDocument/RequestRunInstructionProvider.tsx +4 -3
  27. package/src/assistDocument/components/AssistDocumentForm.tsx +25 -24
  28. package/src/assistDocument/components/FieldRefPreview.tsx +4 -3
  29. package/src/assistDocument/components/InstructionsArrayInput.tsx +4 -3
  30. package/src/assistDocument/components/SelectedFieldContext.tsx +1 -1
  31. package/src/assistDocument/components/helpers.ts +4 -4
  32. package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +3 -2
  33. package/src/assistDocument/components/instruction/FieldRefInput.tsx +5 -4
  34. package/src/assistDocument/components/instruction/InstructionInput.tsx +3 -2
  35. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +2 -1
  36. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +14 -13
  37. package/src/assistDocument/components/instruction/PromptInput.tsx +4 -3
  38. package/src/assistDocument/components/instruction/appearance/IconInput.tsx +2 -2
  39. package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +1 -1
  40. package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +7 -6
  41. package/src/assistDocument/hooks/useInstructionToaster.tsx +6 -5
  42. package/src/assistDocument/hooks/useStudioAssistDocument.ts +14 -13
  43. package/src/assistFormComponents/AssistField.tsx +9 -8
  44. package/src/assistFormComponents/AssistFormBlock.tsx +5 -4
  45. package/src/assistFormComponents/AssistInlineFormBlock.tsx +1 -1
  46. package/src/assistFormComponents/AssistItem.tsx +3 -2
  47. package/src/assistFormComponents/validation/listItem.tsx +2 -2
  48. package/src/assistFormComponents/validation/validationList.tsx +3 -2
  49. package/src/assistInspector/AssistInspector.tsx +16 -15
  50. package/src/assistInspector/FieldAutocomplete.tsx +4 -3
  51. package/src/assistInspector/InstructionTaskHistoryButton.tsx +19 -18
  52. package/src/assistInspector/helpers.ts +10 -9
  53. package/src/assistInspector/index.ts +4 -3
  54. package/src/assistLayout/AiAssistanceConfigContext.tsx +1 -0
  55. package/src/assistLayout/AssistLayout.tsx +5 -4
  56. package/src/assistLayout/RunInstructionProvider.tsx +18 -15
  57. package/src/components/FadeInContent.tsx +1 -1
  58. package/src/components/HideReferenceChangedBannerInput.tsx +1 -1
  59. package/src/components/ImageContext.tsx +4 -3
  60. package/src/components/SafeValueInput.tsx +7 -6
  61. package/src/components/TimeAgo.tsx +1 -1
  62. package/src/fieldActions/assistFieldActions.tsx +31 -30
  63. package/src/fieldActions/generateCaptionActions.tsx +8 -7
  64. package/src/fieldActions/generateImageActions.tsx +6 -5
  65. package/src/helpers/assistSupported.ts +1 -0
  66. package/src/helpers/conditionalMembers.test.ts +2 -1
  67. package/src/helpers/conditionalMembers.ts +17 -14
  68. package/src/helpers/misc.ts +3 -2
  69. package/src/helpers/typeUtils.ts +1 -1
  70. package/src/helpers/useAssistSupported.ts +2 -1
  71. package/src/onboarding/FieldActionsOnboarding.tsx +2 -1
  72. package/src/onboarding/FirstAssistedPathProvider.tsx +4 -3
  73. package/src/onboarding/InspectorOnboarding.tsx +3 -2
  74. package/src/onboarding/onboardingStore.ts +1 -1
  75. package/src/presence/AiFieldPresence.tsx +3 -1
  76. package/src/presence/AssistDocumentPresence.tsx +7 -6
  77. package/src/presence/useAssistPresence.ts +6 -3
  78. package/src/schemas/assistDocumentSchema.tsx +21 -20
  79. package/src/schemas/contextDocumentSchema.tsx +3 -2
  80. package/src/schemas/index.ts +2 -1
  81. package/src/schemas/serialize/SchemTypeTool.tsx +4 -3
  82. package/src/schemas/serialize/serializeSchema.test.ts +3 -2
  83. package/src/schemas/serialize/serializeSchema.ts +15 -14
  84. package/src/schemas/serializedSchemaTypeSchema.ts +2 -1
  85. package/src/translate/FieldTranslationProvider.tsx +33 -25
  86. package/src/translate/getLanguageParams.ts +3 -3
  87. package/src/translate/paths.test.ts +11 -4
  88. package/src/translate/paths.ts +12 -11
  89. package/src/translate/translateActions.tsx +12 -11
  90. package/src/translate/types.ts +2 -2
  91. package/src/useApiClient.ts +9 -9
@@ -1,9 +1,10 @@
1
- import {useContext} from 'react'
2
- import {useSelectedField} from '../../assistInspector/helpers'
3
1
  import {Box, Flex, Text} from '@sanity/ui'
2
+ import {useContext} from 'react'
4
3
  import {PreviewProps} from 'sanity'
5
- import {SelectedFieldContext} from './SelectedFieldContext'
4
+
6
5
  import {InlineBlockValueContext} from '../../assistFormComponents/AssistInlineFormBlock'
6
+ import {useSelectedField} from '../../assistInspector/helpers'
7
+ import {SelectedFieldContext} from './SelectedFieldContext'
7
8
 
8
9
  export function FieldRefPreview(props: PreviewProps & {path?: string}) {
9
10
  const documentSchema = useContext(SelectedFieldContext)?.documentSchema
@@ -1,5 +1,6 @@
1
- import {ArrayOfObjectsInputProps, useCurrentUser} from 'sanity'
2
1
  import {useMemo} from 'react'
2
+ import {ArrayOfObjectsInputProps, useCurrentUser} from 'sanity'
3
+
3
4
  import {StudioInstruction} from '../../types'
4
5
 
5
6
  export function InstructionsArrayInput(props: ArrayOfObjectsInputProps) {
@@ -9,7 +10,7 @@ export function InstructionsArrayInput(props: ArrayOfObjectsInputProps) {
9
10
  const originalMembers = props.members
10
11
  const value = useMemo(
11
12
  () => (originalValue ?? []).filter((v) => !v.userId || v.userId === user?.id),
12
- [originalValue, user]
13
+ [originalValue, user],
13
14
  )
14
15
  const members = useMemo(
15
16
  () =>
@@ -20,7 +21,7 @@ export function InstructionsArrayInput(props: ArrayOfObjectsInputProps) {
20
21
  const value = v?.item?.value as any
21
22
  return !value.userId || value.userId === user?.id
22
23
  }),
23
- [originalMembers, user]
24
+ [originalMembers, user],
24
25
  )
25
26
  return props.renderDefault({...props, value, members})
26
27
  }
@@ -1,5 +1,5 @@
1
- import {ObjectSchemaType, SchemaType} from 'sanity'
2
1
  import {createContext} from 'react'
2
+ import {ObjectSchemaType, SchemaType} from 'sanity'
3
3
 
4
4
  export interface SelectedFieldContextValue {
5
5
  documentSchema?: ObjectSchemaType
@@ -2,20 +2,20 @@ import {FieldError, FieldMember, FieldSetMember, ObjectMember} from 'sanity'
2
2
 
3
3
  export function findFieldMember(
4
4
  members: ObjectMember[],
5
- fieldName: string
5
+ fieldName: string,
6
6
  ): FieldMember | FieldError | undefined {
7
7
  return members.find(
8
8
  (m): m is FieldMember | FieldError =>
9
9
  (m.kind === 'field' && m.name === fieldName) ||
10
- (m.kind === 'error' && m.fieldName === fieldName)
10
+ (m.kind === 'error' && m.fieldName === fieldName),
11
11
  )
12
12
  }
13
13
 
14
14
  export function findFieldsetMember(
15
15
  members: ObjectMember[],
16
- fieldsetName: string
16
+ fieldsetName: string,
17
17
  ): FieldSetMember | undefined {
18
18
  return members.find(
19
- (m): m is FieldSetMember => m.kind === 'fieldSet' && m.fieldSet.name === fieldsetName
19
+ (m): m is FieldSetMember => m.kind === 'fieldSet' && m.fieldSet.name === fieldsetName,
20
20
  )
21
21
  }
@@ -1,16 +1,17 @@
1
1
  import {ArrowLeftIcon} from '@sanity/icons'
2
2
  import {Button} from '@sanity/ui'
3
3
  import {useCallback} from 'react'
4
- import {instructionParam} from '../../../types'
5
4
  import {useDocumentPane} from 'sanity/desk'
5
+
6
6
  import {aiInspectorId} from '../../../assistInspector/constants'
7
+ import {instructionParam} from '../../../types'
7
8
 
8
9
  export function BackToInstructionListLink() {
9
10
  const {openInspector} = useDocumentPane()
10
11
 
11
12
  const goBack = useCallback(
12
13
  () => openInspector(aiInspectorId, {[instructionParam]: undefined as any}),
13
- [openInspector]
14
+ [openInspector],
14
15
  )
15
16
 
16
17
  return (
@@ -1,10 +1,11 @@
1
- import {set, StringInputProps} from 'sanity'
2
- import {useCallback, useContext, useEffect, useId, useRef} from 'react'
3
1
  import {Box} from '@sanity/ui'
4
- import {SelectedFieldContext} from '../SelectedFieldContext'
2
+ import {useCallback, useContext, useEffect, useId, useRef} from 'react'
3
+ import {set, StringInputProps} from 'sanity'
4
+
5
5
  import {FieldAutocomplete} from '../../../assistInspector/FieldAutocomplete'
6
6
  import {FieldRef} from '../../../assistInspector/helpers'
7
7
  import {TypePathContext} from '../AssistDocumentForm'
8
+ import {SelectedFieldContext} from '../SelectedFieldContext'
8
9
 
9
10
  export function FieldRefPathInput(props: StringInputProps) {
10
11
  const documentSchema = useContext(SelectedFieldContext)?.documentSchema
@@ -33,7 +34,7 @@ export function FieldRefPathInput(props: StringInputProps) {
33
34
  const mustStartWith = fieldSegments.slice(0, lastArrayItemIndex + 1).join('.')
34
35
  return typePath.startsWith(mustStartWith)
35
36
  },
36
- [typePath]
37
+ [typePath],
37
38
  )
38
39
  if (!documentSchema) {
39
40
  return props.renderDefault(props)
@@ -1,7 +1,8 @@
1
- import {FieldError, FieldMember, ObjectInputMember, ObjectInputProps} from 'sanity'
2
- import {findFieldMember, findFieldsetMember} from '../helpers'
3
1
  import {Box, Flex, Stack, Text} from '@sanity/ui'
4
2
  import {useId, useMemo} from 'react'
3
+ import {FieldError, FieldMember, ObjectInputMember, ObjectInputProps} from 'sanity'
4
+
5
+ import {findFieldMember, findFieldsetMember} from '../helpers'
5
6
 
6
7
  export function InstructionInput(props: ObjectInputProps) {
7
8
  return (
@@ -1,3 +1,4 @@
1
+ import {useCallback, useContext, useState} from 'react'
1
2
  import {
2
3
  ArrayFieldProps,
3
4
  ArraySchemaType,
@@ -5,7 +6,7 @@ import {
5
6
  isObjectSchemaType,
6
7
  ObjectSchemaType,
7
8
  } from 'sanity'
8
- import {useCallback, useContext, useState} from 'react'
9
+
9
10
  import {SelectedFieldContext} from '../SelectedFieldContext'
10
11
 
11
12
  export function InstructionOutputField(props: ArrayFieldProps) {
@@ -1,3 +1,5 @@
1
+ import {Card, Checkbox, Flex, Stack, Text} from '@sanity/ui'
2
+ import {useCallback, useContext, useEffect, useMemo} from 'react'
1
3
  import {
2
4
  ArrayOfObjectsInputProps,
3
5
  ArraySchemaType,
@@ -11,12 +13,11 @@ import {
11
13
  typed,
12
14
  unset,
13
15
  } from 'sanity'
14
- import {useCallback, useContext, useEffect, useMemo} from 'react'
15
- import {SelectedFieldContext} from '../SelectedFieldContext'
16
- import {Card, Checkbox, Flex, Stack, Text} from '@sanity/ui'
17
- import {isType} from '../../../helpers/typeUtils'
16
+
18
17
  import {isAssistSupported} from '../../../helpers/assistSupported'
18
+ import {isType} from '../../../helpers/typeUtils'
19
19
  import {OutputFieldItem, outputFieldTypeName, OutputTypeItem} from '../../../types'
20
+ import {SelectedFieldContext} from '../SelectedFieldContext'
20
21
 
21
22
  export function InstructionOutputInput(props: ArrayOfObjectsInputProps) {
22
23
  const {fieldSchema} = useContext(SelectedFieldContext) ?? {}
@@ -38,13 +39,13 @@ export function InstructionOutputInput(props: ArrayOfObjectsInputProps) {
38
39
  function useEmptySelectAllValue(
39
40
  value: (OutputTypeItem | OutputFieldItem)[],
40
41
  allowedValues: {name: string}[],
41
- onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void
42
+ onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void,
42
43
  ) {
43
44
  useEffect(() => {
44
45
  const validValues = value?.filter((v) =>
45
46
  allowedValues.find(
46
- (f) => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type)
47
- )
47
+ (f) => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type),
48
+ ),
48
49
  )
49
50
  const valueLength = value?.length ?? 0
50
51
  const validLength = validValues?.length ?? 0
@@ -65,7 +66,7 @@ function ObjectOutputInput({
65
66
 
66
67
  const fields = useMemo(
67
68
  () => fieldSchema.fields.filter((field) => isAssistSupported(field.type)),
68
- [fieldSchema.fields]
69
+ [fieldSchema.fields],
69
70
  )
70
71
 
71
72
  useEmptySelectAllValue(value as OutputTypeItem[], fields, onChange)
@@ -84,7 +85,7 @@ function ObjectOutputInput({
84
85
  _key: field.name,
85
86
  _type: 'sanity.assist.output.field',
86
87
  relativePath: field.name,
87
- })
88
+ }),
88
89
  )
89
90
  onChange(PatchEvent.from([setIfMissing([]), insert(items, 'after', [-1])]))
90
91
  }
@@ -97,7 +98,7 @@ function ObjectOutputInput({
97
98
  onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], 'after', [-1])]))
98
99
  }
99
100
  },
100
- [onChange, value, fields]
101
+ [onChange, value, fields],
101
102
  )
102
103
 
103
104
  return (
@@ -126,7 +127,7 @@ function ArrayOutputInput({
126
127
 
127
128
  const ofItems = useMemo(
128
129
  () => fieldSchema.of.filter((itemType) => isAssistSupported(itemType)),
129
- [fieldSchema.of]
130
+ [fieldSchema.of],
130
131
  )
131
132
 
132
133
  useEmptySelectAllValue(value as OutputTypeItem[], ofItems, onChange)
@@ -145,7 +146,7 @@ function ArrayOutputInput({
145
146
  _key: field.name,
146
147
  _type: 'sanity.assist.output.type',
147
148
  type: field.name,
148
- })
149
+ }),
149
150
  )
150
151
  onChange(PatchEvent.from([setIfMissing([]), insert(items, 'after', [-1])]))
151
152
  }
@@ -158,7 +159,7 @@ function ArrayOutputInput({
158
159
  onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], 'after', [-1])]))
159
160
  }
160
161
  },
161
- [onChange, value, ofItems]
162
+ [onChange, value, ofItems],
162
163
  )
163
164
  return (
164
165
  <Stack space={2}>
@@ -1,9 +1,10 @@
1
- import {ArrayOfObjectsInputProps, set, typed} from 'sanity'
2
1
  import {Box} from '@sanity/ui'
3
- import styled from 'styled-components'
4
2
  import {useEffect} from 'react'
5
- import {ContextBlock, FieldRef, PromptBlock, PromptTextBlock, UserInputBlock} from '../../../types'
3
+ import {ArrayOfObjectsInputProps, set, typed} from 'sanity'
4
+ import styled from 'styled-components'
5
+
6
6
  import {randomKey} from '../../../_lib/randomKey'
7
+ import {ContextBlock, FieldRef, PromptBlock, PromptTextBlock, UserInputBlock} from '../../../types'
7
8
 
8
9
  const PteMods = styled(Box)`
9
10
  & [data-testid='pt-editor__toolbar-card'] > div > div:last-child {
@@ -1,7 +1,7 @@
1
1
  import {icons} from '@sanity/icons'
2
- import {set, StringInputProps} from 'sanity'
3
2
  import {Button, Menu, MenuButton, MenuItem} from '@sanity/ui'
4
3
  import {ElementType, ReactNode, useCallback, useId, useMemo} from 'react'
4
+ import {set, StringInputProps} from 'sanity'
5
5
 
6
6
  export function IconInput(props: StringInputProps) {
7
7
  const {value, onChange} = props
@@ -11,7 +11,7 @@ export function IconInput(props: StringInputProps) {
11
11
  Object.entries(icons).map(([key, icon]) => (
12
12
  <IconItem key={key} iconKey={key} icon={icon} onChange={onChange} />
13
13
  )),
14
- [onChange]
14
+ [onChange],
15
15
  )
16
16
 
17
17
  const selectedIcon = useMemo(() => getIcon(value), [value])
@@ -1,6 +1,6 @@
1
- import {set, StringInputProps, unset, useCurrentUser} from 'sanity'
2
1
  import {Card, Flex, Switch, Text} from '@sanity/ui'
3
2
  import {useCallback, useId} from 'react'
3
+ import {set, StringInputProps, unset, useCurrentUser} from 'sanity'
4
4
 
5
5
  export function InstructionVisibility(props: StringInputProps) {
6
6
  const {value, onChange} = props
@@ -1,20 +1,21 @@
1
- import {getPublishedId, ObjectSchemaType, useEditState} from 'sanity'
2
- import {useStudioAssistDocument} from './useStudioAssistDocument'
3
- import {AssistDocumentContextValue} from '../AssistDocumentContext'
4
1
  import {useMemo} from 'react'
5
- import {isDocAssistable} from '../RequestRunInstructionProvider'
2
+ import {getPublishedId, ObjectSchemaType, useEditState} from 'sanity'
6
3
  import {useDocumentPane} from 'sanity/desk'
4
+
7
5
  import {useAiPaneRouter} from '../../assistInspector/helpers'
8
6
  import {fieldPathParam} from '../../types'
7
+ import {AssistDocumentContextValue} from '../AssistDocumentContext'
8
+ import {isDocAssistable} from '../RequestRunInstructionProvider'
9
+ import {useStudioAssistDocument} from './useStudioAssistDocument'
9
10
 
10
11
  export function useAssistDocumentContextValue(
11
12
  documentId: string,
12
- documentSchemaType: ObjectSchemaType
13
+ documentSchemaType: ObjectSchemaType,
13
14
  ) {
14
15
  const {published, draft} = useEditState(
15
16
  getPublishedId(documentId),
16
17
  documentSchemaType.name,
17
- 'low'
18
+ 'low',
18
19
  )
19
20
  const assistableDocumentId = draft?._id || published?._id || documentId
20
21
  const documentIsNew = Boolean(!draft?._id && !published?._id)
@@ -1,10 +1,11 @@
1
- import {useEffect, useRef} from 'react'
2
- import {InstructionTask} from '../../types'
1
+ import {useToast} from '@sanity/ui'
3
2
  import {addSeconds, isAfter} from 'date-fns'
3
+ import {useEffect, useRef} from 'react'
4
+ import {ObjectSchemaType, useCurrentUser} from 'sanity'
5
+
4
6
  import {getInstructionTitle} from '../../helpers/misc'
7
+ import {InstructionTask} from '../../types'
5
8
  import {useStudioAssistDocument} from './useStudioAssistDocument'
6
- import {ObjectSchemaType, useCurrentUser} from 'sanity'
7
- import {useToast} from '@sanity/ui'
8
9
 
9
10
  const NO_TASKS: InstructionTask[] = []
10
11
 
@@ -24,7 +25,7 @@ export function useInstructionToaster(documentId: string, documentSchemaType: Ob
24
25
 
25
26
  if (previousTasks.current !== 'initial') {
26
27
  const prevTaskByKey = Object.fromEntries(
27
- (previousTasks.current ?? NO_TASKS).map((run) => [run._key, run])
28
+ (previousTasks.current ?? NO_TASKS).map((run) => [run._key, run]),
28
29
  )
29
30
  const endedTasks = tasks
30
31
  ?.filter((task) => task.startedByUserId === currentUser?.id)
@@ -1,17 +1,18 @@
1
1
  import {useEffect, useMemo} from 'react'
2
+ import {type ObjectSchemaType, typed, useClient, useCurrentUser} from 'sanity'
3
+
4
+ import {maxHistoryVisibilityMs} from '../../constants'
5
+ import {assistDocumentId, assistTasksStatusId} from '../../helpers/ids'
2
6
  import {
3
7
  assistDocumentTypeName,
4
- AssistTasksStatus,
8
+ type AssistTasksStatus,
5
9
  assistTasksStatusTypeName,
6
- InstructionTask,
7
- StudioAssistDocument,
8
- StudioAssistField,
9
- StudioInstruction,
10
+ type InstructionTask,
11
+ type StudioAssistDocument,
12
+ type StudioAssistField,
13
+ type StudioInstruction,
10
14
  } from '../../types'
11
- import {ObjectSchemaType, typed, useClient, useCurrentUser} from 'sanity'
12
15
  import {useDocumentState} from './useDocumentState'
13
- import {assistDocumentId, assistTasksStatusId} from '../../helpers/ids'
14
- import {maxHistoryVisibilityMs} from '../../constants'
15
16
 
16
17
  interface UseAssistDocumentProps {
17
18
  documentId: string
@@ -29,11 +30,11 @@ export function useStudioAssistDocument({
29
30
 
30
31
  const assistDocument = useDocumentState<StudioAssistDocument>(
31
32
  assistDocumentId(documentTypeName),
32
- assistDocumentTypeName
33
+ assistDocumentTypeName,
33
34
  )
34
35
  const assistTasksStatus = useDocumentState<AssistTasksStatus>(
35
36
  assistTasksStatusId(documentId ?? ''),
36
- assistTasksStatusTypeName
37
+ assistTasksStatusTypeName,
37
38
  )
38
39
 
39
40
  const client = useClient({apiVersion: '2023-01-01'})
@@ -45,7 +46,7 @@ export function useStudioAssistDocument({
45
46
  _id: assistDocumentId(documentTypeName),
46
47
  _type: assistDocumentTypeName,
47
48
  })
48
- .catch((e) => {
49
+ .catch(() => {
49
50
  // best effort
50
51
  })
51
52
  }
@@ -83,7 +84,7 @@ export function useStudioAssistDocument({
83
84
 
84
85
  function asStudioInstruction(
85
86
  instruction: StudioInstruction,
86
- run: InstructionTask[]
87
+ run: InstructionTask[],
87
88
  ): StudioInstruction {
88
89
  return {
89
90
  ...instruction,
@@ -92,7 +93,7 @@ function asStudioInstruction(
92
93
  .filter(
93
94
  (task) =>
94
95
  task.started &&
95
- new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs
96
+ new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs,
96
97
  ),
97
98
  }
98
99
  }
@@ -1,15 +1,16 @@
1
- import {FieldProps, isArraySchemaType, pathToString} from 'sanity'
2
- import {useAssistPresence} from '../presence/useAssistPresence'
3
- import {useContext, useMemo} from 'react'
4
1
  import {Box, Flex} from '@sanity/ui'
5
- import {contextDocumentTypeName} from '../types'
2
+ import {useContext, useMemo} from 'react'
3
+ import {FieldProps, isArraySchemaType, pathToString} from 'sanity'
4
+
5
+ import {assistFormId} from '../_lib/form/constants'
6
6
  import {isAssistSupported} from '../helpers/assistSupported'
7
7
  import {isPortableTextArray, isType} from '../helpers/typeUtils'
8
- import {AiFieldPresence} from '../presence/AiFieldPresence'
9
8
  import {AssistOnboardingPopover} from '../onboarding/FieldActionsOnboarding'
10
9
  import {FirstAssistedPathContext} from '../onboarding/FirstAssistedPathProvider'
11
10
  import {fieldOnboardingKey, useOnboardingFeature} from '../onboarding/onboardingStore'
12
- import {assistFormId} from '../_lib/form/constants'
11
+ import {AiFieldPresence} from '../presence/AiFieldPresence'
12
+ import {useAssistPresence} from '../presence/useAssistPresence'
13
+ import {contextDocumentTypeName} from '../types'
13
14
 
14
15
  export function AssistFieldWrapper(props: FieldProps) {
15
16
  const {schemaType} = props
@@ -39,7 +40,7 @@ export function AssistField(props: FieldProps) {
39
40
 
40
41
  const isPortableText = useMemo(
41
42
  () => !!(isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType)),
42
- [props.schemaType]
43
+ [props.schemaType],
43
44
  )
44
45
 
45
46
  const presence = useAssistPresence(props.path, isPortableText)
@@ -47,7 +48,7 @@ export function AssistField(props: FieldProps) {
47
48
  const firstAssistedPath = useContext(FirstAssistedPathContext)
48
49
  const isFirstAssisted = useMemo(
49
50
  () => pathToString(path) === firstAssistedPath,
50
- [path, firstAssistedPath]
51
+ [path, firstAssistedPath],
51
52
  )
52
53
 
53
54
  const {showOnboarding, dismissOnboarding} = useOnboardingFeature(fieldOnboardingKey)
@@ -1,9 +1,10 @@
1
- import {BlockProps, PatchEvent, useFormCallbacks} from 'sanity'
2
- import {useAssistPresence} from '../presence/useAssistPresence'
3
1
  import {Box, Flex} from '@sanity/ui'
4
- import {ErrorWrapper} from '../components/SafeValueInput'
5
2
  import {useCallback} from 'react'
3
+ import {BlockProps, PatchEvent, useFormCallbacks} from 'sanity'
4
+
5
+ import {ErrorWrapper} from '../components/SafeValueInput'
6
6
  import {AiFieldPresence} from '../presence/AiFieldPresence'
7
+ import {useAssistPresence} from '../presence/useAssistPresence'
7
8
 
8
9
  export function AssistFormBlock(props: BlockProps) {
9
10
  const presence = useAssistPresence(props.path, true)
@@ -16,7 +17,7 @@ export function AssistFormBlock(props: BlockProps) {
16
17
  }
17
18
  onChange(PatchEvent.from(patchEvent).prefixAll({_key: key}))
18
19
  },
19
- [onChange, key]
20
+ [onChange, key],
20
21
  )
21
22
  const singlePresence = presence[0]
22
23
  return (
@@ -1,5 +1,5 @@
1
- import {BlockProps} from 'sanity'
2
1
  import {createContext} from 'react'
2
+ import {BlockProps} from 'sanity'
3
3
 
4
4
  // workaround for preview value sometimes lagging behind
5
5
  export const InlineBlockValueContext = createContext<unknown>(undefined)
@@ -1,7 +1,8 @@
1
- import {ItemProps} from 'sanity'
2
- import {useAssistPresence} from '../presence/useAssistPresence'
3
1
  import {Box, Flex} from '@sanity/ui'
2
+ import {ItemProps} from 'sanity'
3
+
4
4
  import {AiFieldPresence} from '../presence/AiFieldPresence'
5
+ import {useAssistPresence} from '../presence/useAssistPresence'
5
6
 
6
7
  export function AssistItem(props: ItemProps) {
7
8
  const {path} = props
@@ -1,6 +1,6 @@
1
- import {Path, ValidationMarker} from 'sanity'
2
- import {useCallback} from 'react'
3
1
  import {Box, ButtonTone, Flex, MenuItem, Stack, Text} from '@sanity/ui'
2
+ import {useCallback} from 'react'
3
+ import {Path, ValidationMarker} from 'sanity'
4
4
  import styled from 'styled-components'
5
5
 
6
6
  interface ValidationListItemProps {
@@ -1,3 +1,4 @@
1
+ import {Container} from '@sanity/ui'
1
2
  import {useCallback} from 'react'
2
3
  import {
3
4
  isValidationErrorMarker,
@@ -7,7 +8,7 @@ import {
7
8
  Path,
8
9
  ValidationMarker,
9
10
  } from 'sanity'
10
- import {Container} from '@sanity/ui'
11
+
11
12
  import {ListItem} from './listItem'
12
13
 
13
14
  /** @internal */
@@ -31,7 +32,7 @@ export function ValidationList(props: ValidationListProps) {
31
32
  if (onFocus) onFocus(path)
32
33
  if (onClose) onClose()
33
34
  },
34
- [onFocus, onClose]
35
+ [onFocus, onClose],
35
36
  )
36
37
 
37
38
  const resolvePathTitle = (path: Path) => {
@@ -13,25 +13,26 @@ import {
13
13
  DocumentPaneProvider,
14
14
  useDocumentPane,
15
15
  } from 'sanity/desk'
16
- import {DocumentForm} from '../_lib/form'
17
- import {assistDocumentTypeName, fieldPathParam, instructionParam} from '../types'
18
- import {FieldRef, getFieldTitle, useAiPaneRouter, useSelectedField, useTypePath} from './helpers'
19
16
  import styled from 'styled-components'
17
+
18
+ import {DocumentForm} from '../_lib/form'
19
+ import {TypePathContext} from '../assistDocument/components/AssistDocumentForm'
20
20
  import {useStudioAssistDocument} from '../assistDocument/hooks/useStudioAssistDocument'
21
- import {InstructionTaskHistoryButton} from './InstructionTaskHistoryButton'
22
- import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
23
- import {giveFeedbackUrl, pluginTitle, releaseAnnouncementUrl, salesUrl} from '../constants'
24
- import {assistDocumentId} from '../helpers/ids'
25
21
  import {
26
22
  getAssistableDocId,
27
23
  isDocAssistable,
28
24
  useRequestRunInstruction,
29
25
  } from '../assistDocument/RequestRunInstructionProvider'
26
+ import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
27
+ import {giveFeedbackUrl, pluginTitle, releaseAnnouncementUrl, salesUrl} from '../constants'
28
+ import {getConditionalMembers} from '../helpers/conditionalMembers'
29
+ import {assistDocumentId} from '../helpers/ids'
30
30
  import {InspectorOnboarding} from '../onboarding/InspectorOnboarding'
31
31
  import {inspectorOnboardingKey, useOnboardingFeature} from '../onboarding/onboardingStore'
32
- import {TypePathContext} from '../assistDocument/components/AssistDocumentForm'
32
+ import {assistDocumentTypeName, fieldPathParam, instructionParam} from '../types'
33
33
  import {FieldTitle} from './FieldAutocomplete'
34
- import {getConditionalMembers} from '../helpers/conditionalMembers'
34
+ import {FieldRef, getFieldTitle, useAiPaneRouter, useSelectedField, useTypePath} from './helpers'
35
+ import {InstructionTaskHistoryButton} from './InstructionTaskHistoryButton'
35
36
 
36
37
  const CardWithShadowBelow = styled(Card)`
37
38
  position: relative;
@@ -172,8 +173,8 @@ export function AssistInspectorWrapper(props: DocumentInspectorProps) {
172
173
  context.error
173
174
  ? 'Retry'
174
175
  : status?.initialized && !status.validToken
175
- ? `Restore ${pluginTitle}`
176
- : `Enable ${pluginTitle} now`
176
+ ? `Restore ${pluginTitle}`
177
+ : `Enable ${pluginTitle} now`
177
178
  }
178
179
  tone="primary"
179
180
  onClick={context.init}
@@ -224,11 +225,11 @@ export function AssistInspector(props: DocumentInspectorProps) {
224
225
  const tasks = useMemo(
225
226
  () =>
226
227
  assistDocument?.tasks?.filter((i) => !instructionKey || i.instructionKey === instructionKey),
227
- [assistDocument?.tasks, instructionKey]
228
+ [assistDocument?.tasks, instructionKey],
228
229
  )
229
230
  const instructions = useMemo(
230
231
  () => assistDocument?.fields?.flatMap((f) => f.instructions ?? []),
231
- [assistDocument?.fields]
232
+ [assistDocument?.fields],
232
233
  )
233
234
 
234
235
  const promptValue = instruction?.prompt
@@ -252,7 +253,7 @@ export function AssistInspector(props: DocumentInspectorProps) {
252
253
  type: assistDocumentTypeName,
253
254
  },
254
255
  }),
255
- [aiDocId]
256
+ [aiDocId],
256
257
  )
257
258
 
258
259
  const runCurrentInstruction = useCallback(
@@ -268,7 +269,7 @@ export function AssistInspector(props: DocumentInspectorProps) {
268
269
  instruction,
269
270
  conditionalMembers: formStateRef.current ? getConditionalMembers(formStateRef.current) : [],
270
271
  }),
271
- [pathKey, instruction, typePath, documentType, assistableDocId, requestRunInstruction]
272
+ [pathKey, instruction, typePath, documentType, assistableDocId, requestRunInstruction],
272
273
  )
273
274
 
274
275
  const Region = useCallback((_props: any) => {
@@ -1,9 +1,10 @@
1
1
  import {SearchIcon} from '@sanity/icons'
2
2
  import {Autocomplete, Box, Breadcrumbs, Card, Flex, Text} from '@sanity/ui'
3
3
  import {createElement, useCallback, useMemo} from 'react'
4
- import {FieldRef, getFieldRefs, getFieldRefsWithDocument} from './helpers'
5
4
  import {ObjectSchemaType} from 'sanity'
5
+
6
6
  import {isType} from '../helpers/typeUtils'
7
+ import {FieldRef, getFieldRefs, getFieldRefsWithDocument} from './helpers'
7
8
 
8
9
  interface FieldSelectorProps {
9
10
  id: string
@@ -25,7 +26,7 @@ export function FieldAutocomplete(props: FieldSelectorProps) {
25
26
  }, [schemaType, includeDocument])
26
27
  const currentField = useMemo(
27
28
  () => fieldRefs.find((f) => f.key === fieldPath),
28
- [fieldPath, fieldRefs]
29
+ [fieldPath, fieldRefs],
29
30
  )
30
31
 
31
32
  const autocompleteOptions = useMemo(
@@ -34,7 +35,7 @@ export function FieldAutocomplete(props: FieldSelectorProps) {
34
35
  .filter((field) => (filter ? filter(field) : true))
35
36
  .filter((f) => !isType(f.schemaType, 'reference'))
36
37
  .map((field) => ({value: field.key, field})),
37
- [fieldRefs, filter]
38
+ [fieldRefs, filter],
38
39
  )
39
40
 
40
41
  const renderOption = useCallback((option: {value: string; field: FieldRef}) => {