@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
@@ -1,57 +0,0 @@
1
- import {DocumentTextIcon, TokenIcon} from '@sanity/icons'
2
- import {defineArrayMember, defineField, defineType} from 'sanity'
3
-
4
- import {HideReferenceChangedBannerInput} from '../components/HideReferenceChangedBannerInput'
5
- import {contextDocumentTypeName} from '../types'
6
-
7
- export const contextDocumentSchema = defineType({
8
- type: 'document',
9
- name: contextDocumentTypeName,
10
- title: 'AI context',
11
- liveEdit: true,
12
- icon: TokenIcon,
13
- components: {
14
- input: HideReferenceChangedBannerInput,
15
- },
16
- fields: [
17
- defineField({
18
- type: 'string',
19
- name: 'title',
20
- title: 'Title',
21
- }),
22
- defineField({
23
- name: 'context',
24
- type: 'array',
25
- title: 'Context',
26
- of: [
27
- defineArrayMember({
28
- type: 'block',
29
- styles: [{title: 'Normal', value: 'normal'}],
30
- lists: [],
31
- marks: {
32
- decorators: [],
33
- annotations: [],
34
- },
35
- }),
36
- ],
37
- }),
38
- ],
39
- preview: {
40
- select: {
41
- title: 'title',
42
- context: 'context',
43
- },
44
- prepare({title, context}) {
45
- const text = context
46
- ?.flatMap((block: any) => block?.children)
47
- .flatMap((child: any) => child?.text?.split(' '))
48
- .filter(Boolean)
49
- const words = text?.length ?? 0
50
- return {
51
- title,
52
- subtitle: `Words: ${words}`,
53
- media: DocumentTextIcon,
54
- }
55
- },
56
- },
57
- })
@@ -1,69 +0,0 @@
1
- /* eslint-disable camelcase */
2
- import {ArrayOfType, FieldProps, SchemaTypeDefinition} from 'sanity'
3
-
4
- import {
5
- assistDocumentSchema,
6
- documentInstructionStatus,
7
- fieldInstructions,
8
- fieldReference,
9
- instruction,
10
- instructionTask,
11
- outputFieldType,
12
- outputTypeType,
13
- prompt,
14
- promptContext,
15
- userInput,
16
- } from './assistDocumentSchema'
17
- import {contextDocumentSchema} from './contextDocumentSchema'
18
-
19
- function excludeComments<T extends SchemaTypeDefinition | ArrayOfType>(type: T): T {
20
- const existingRender = (type as any)?.components?.field
21
- return {
22
- ...type,
23
- ...('components' in type
24
- ? {
25
- components: {
26
- ...type.components,
27
- field: (props: FieldProps) => {
28
- const newProps = {...props, ...{__internal_comments: undefined}}
29
- if (typeof existingRender === 'function') {
30
- return existingRender(newProps)
31
- }
32
- return props.renderDefault(newProps)
33
- },
34
- },
35
- }
36
- : {}),
37
- ...('fields' in type
38
- ? {
39
- // recursively disable comments in fields
40
- fields: type.fields?.map((field) => excludeComments(field)),
41
- }
42
- : {}),
43
- ...('of' in type
44
- ? {
45
- // recursively disable comments in array items
46
- of: type.of?.map((arrayItemType) => excludeComments(arrayItemType)),
47
- }
48
- : {}),
49
- }
50
- }
51
-
52
- const instructionForm = [
53
- fieldInstructions,
54
- instruction,
55
- fieldReference,
56
- prompt,
57
- userInput,
58
- promptContext,
59
- ].map(excludeComments)
60
-
61
- export const schemaTypes = [
62
- ...instructionForm,
63
- outputFieldType,
64
- outputTypeType,
65
- assistDocumentSchema,
66
- documentInstructionStatus,
67
- instructionTask,
68
- contextDocumentSchema,
69
- ]
@@ -1,103 +0,0 @@
1
- import {SyncIcon} from '@sanity/icons'
2
- import {Box, Button, Card, Flex, Label, Spinner, Stack} from '@sanity/ui'
3
- import {useCallback, useMemo, useState} from 'react'
4
- import {useClient, useSchema} from 'sanity'
5
-
6
- import {useListeningQuery} from '../../_lib/useListeningQuery'
7
- import {assistSerializedTypeName, SerializedSchemaType} from '../../types'
8
- import {serializeSchema} from './serializeSchema'
9
-
10
- const NO_DATA: SerializedSchemaType[] = []
11
-
12
- const defaultTitle = 'Sync schema'
13
-
14
- export function SchemaTypeTool() {
15
- const schema = useSchema()
16
- const client = useClient({apiVersion: '2023-01-01'})
17
- const [saving, setSaving] = useState(false)
18
- const [syncTitle, setSyncTitle] = useState(defaultTitle)
19
-
20
- const {data} = useListeningQuery<SerializedSchemaType[]>('*[_type==$type] | order(_type)', {
21
- type: assistSerializedTypeName,
22
- })
23
-
24
- const types = useMemo(() => {
25
- return serializeSchema(schema)
26
- }, [schema])
27
-
28
- const storeTypes = useCallback(() => {
29
- setSaving(true)
30
- let canSave = true
31
- async function store() {
32
- setSyncTitle(`Syncing 0/${types.length}`)
33
- const transaction = client.transaction()
34
- for (let i = 0; i < types.length; i++) {
35
- if (!canSave) {
36
- break
37
- }
38
- const type = types[i]
39
- await transaction.createOrReplace(type as Required<typeof type>)
40
- if (i > 0 && i % 50 === 0) {
41
- await transaction.commit()
42
- transaction.reset()
43
- setSyncTitle(`Syncing ${i}/${types.length}`)
44
- }
45
- }
46
- await transaction.commit()
47
- }
48
- store()
49
- .catch(console.error)
50
- .finally(() => {
51
- setSaving(false)
52
- setSyncTitle(defaultTitle)
53
- })
54
- return () => {
55
- canSave = false
56
- setSaving(false)
57
- setSyncTitle(defaultTitle)
58
- }
59
- }, [types, client, setSaving, setSyncTitle])
60
-
61
- return (
62
- <Card padding={4} overflow="auto" style={{height: 'calc(100vh - 81px)'}}>
63
- <Stack space={4}>
64
- <Box>
65
- <Button
66
- icon={saving ? <Spinner style={{marginTop: 5}} /> : SyncIcon}
67
- text={syncTitle}
68
- disabled={saving}
69
- onClick={storeTypes}
70
- />
71
- </Box>
72
- <Flex gap={2}>
73
- <Stack space={2}>
74
- <Label>Studio schema</Label>
75
- <ul>
76
- {types.map((type) => (
77
- <li key={type.name}>
78
- <SchemaEntry schemaStub={type} />
79
- </li>
80
- ))}
81
- </ul>
82
- </Stack>
83
-
84
- <Stack space={2}>
85
- <Label>Stored schema</Label>
86
- <ul>
87
- {(data ?? NO_DATA).map((type) => (
88
- <li key={type.name}>
89
- <SchemaEntry schemaStub={type} />
90
- </li>
91
- ))}
92
- </ul>
93
- </Stack>
94
- </Flex>
95
- </Stack>
96
- </Card>
97
- )
98
- }
99
-
100
- function SchemaEntry({schemaStub}: {schemaStub: SerializedSchemaType}) {
101
- const out = useMemo(() => JSON.stringify(schemaStub, null, 2), [schemaStub])
102
- return <pre>{out}</pre>
103
- }
@@ -1,38 +0,0 @@
1
- import {assistSerializedFieldTypeName, assistSerializedTypeName} from '../../types'
2
-
3
- export const hiddenTypes = [
4
- 'any',
5
- 'array',
6
- 'block',
7
- 'boolean',
8
- 'crossDatasetReference',
9
- 'date',
10
- 'datetime',
11
- 'document',
12
- 'email',
13
- 'file',
14
- 'globalDocumentReference',
15
- 'image',
16
- 'number',
17
- 'object',
18
- 'reference',
19
- 'span',
20
- 'string',
21
- 'text',
22
- 'url',
23
- 'slug',
24
- 'geopoint',
25
- 'sanity.assetSourceData',
26
- 'sanity.imageAsset',
27
- 'sanity.fileAsset',
28
- 'sanity.imageCrop',
29
- 'sanity.imageHotspot',
30
- 'sanity.imageMetadata',
31
- 'sanity.imageDimensions',
32
- 'sanity.imagePalette',
33
- 'sanity.imagePaletteSwatch',
34
-
35
- assistSerializedTypeName,
36
- assistSerializedFieldTypeName,
37
- 'sanity-agent.job.document',
38
- ]