@sanity/assist 2.0.4 → 3.0.0
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.
- package/README.md +2 -2
- package/dist/index.d.mts +377 -0
- package/dist/index.esm.js +3132 -5883
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3109 -5886
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4159 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -37
- package/src/_lib/connector/ConnectFromRegion.tsx +4 -3
- package/src/_lib/connector/ConnectToRegion.tsx +1 -0
- package/src/_lib/connector/ConnectorRegion.tsx +2 -1
- package/src/_lib/connector/ConnectorsProvider.tsx +2 -1
- package/src/_lib/connector/ConnectorsStoreContext.ts +1 -0
- package/src/_lib/connector/index.ts +1 -1
- package/src/_lib/connector/mapConnectorToLine.ts +2 -2
- package/src/_lib/connector/useConnectorsStore.ts +2 -1
- package/src/_lib/connector/useRegionRects.ts +4 -3
- package/src/_lib/fixedListenQuery.ts +11 -11
- package/src/_lib/form/DocumentForm.tsx +11 -9
- package/src/_lib/form/helpers.ts +2 -1
- package/src/_lib/useListeningQuery.ts +4 -3
- package/src/assistConnectors/AssistConnectorsOverlay.tsx +1 -0
- package/src/assistConnectors/ConnectorPath.tsx +3 -2
- package/src/assistConnectors/draw/connectorPath.ts +13 -13
- package/src/assistDocument/AssistDocumentContext.tsx +3 -2
- package/src/assistDocument/AssistDocumentContextProvider.tsx +2 -1
- package/src/assistDocument/AssistDocumentInput.tsx +10 -9
- package/src/assistDocument/RequestRunInstructionProvider.tsx +4 -3
- package/src/assistDocument/components/AssistDocumentForm.tsx +25 -24
- package/src/assistDocument/components/FieldRefPreview.tsx +4 -3
- package/src/assistDocument/components/InstructionsArrayInput.tsx +4 -3
- package/src/assistDocument/components/SelectedFieldContext.tsx +1 -1
- package/src/assistDocument/components/helpers.ts +4 -4
- package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +4 -3
- package/src/assistDocument/components/instruction/FieldRefInput.tsx +5 -4
- package/src/assistDocument/components/instruction/InstructionInput.tsx +3 -2
- package/src/assistDocument/components/instruction/InstructionOutputField.tsx +2 -1
- package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +14 -13
- package/src/assistDocument/components/instruction/PromptInput.tsx +10 -3
- package/src/assistDocument/components/instruction/appearance/IconInput.tsx +2 -2
- package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +1 -1
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +8 -7
- package/src/assistDocument/hooks/useInstructionToaster.tsx +6 -5
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +14 -13
- package/src/assistFormComponents/AssistField.tsx +9 -8
- package/src/assistFormComponents/AssistFormBlock.tsx +5 -4
- package/src/assistFormComponents/AssistInlineFormBlock.tsx +1 -1
- package/src/assistFormComponents/AssistItem.tsx +3 -2
- package/src/assistFormComponents/validation/listItem.tsx +3 -3
- package/src/assistFormComponents/validation/validationList.tsx +3 -2
- package/src/assistInspector/AssistInspector.tsx +25 -18
- package/src/assistInspector/FieldAutocomplete.tsx +4 -3
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +20 -19
- package/src/assistInspector/helpers.ts +16 -15
- package/src/assistInspector/index.ts +4 -3
- package/src/assistLayout/AiAssistanceConfigContext.tsx +1 -0
- package/src/assistLayout/AssistLayout.tsx +5 -4
- package/src/assistLayout/RunInstructionProvider.tsx +18 -15
- package/src/components/FadeInContent.tsx +3 -3
- package/src/components/HideReferenceChangedBannerInput.tsx +1 -1
- package/src/components/ImageContext.tsx +5 -4
- package/src/components/SafeValueInput.tsx +9 -11
- package/src/components/TimeAgo.tsx +1 -1
- package/src/fieldActions/assistFieldActions.tsx +31 -30
- package/src/fieldActions/generateCaptionActions.tsx +8 -7
- package/src/fieldActions/generateImageActions.tsx +6 -5
- package/src/helpers/assistSupported.ts +1 -0
- package/src/helpers/conditionalMembers.test.ts +2 -1
- package/src/helpers/conditionalMembers.ts +17 -14
- package/src/helpers/misc.ts +3 -2
- package/src/helpers/typeUtils.ts +1 -1
- package/src/helpers/useAssistSupported.ts +2 -1
- package/src/onboarding/FieldActionsOnboarding.tsx +2 -1
- package/src/onboarding/FirstAssistedPathProvider.tsx +4 -3
- package/src/onboarding/InspectorOnboarding.tsx +3 -2
- package/src/onboarding/onboardingStore.ts +1 -1
- package/src/presence/AiFieldPresence.tsx +3 -1
- package/src/presence/AssistAvatar.tsx +2 -2
- package/src/presence/AssistDocumentPresence.tsx +7 -6
- package/src/presence/useAssistPresence.ts +6 -3
- package/src/schemas/assistDocumentSchema.tsx +21 -20
- package/src/schemas/contextDocumentSchema.tsx +3 -2
- package/src/schemas/index.ts +2 -1
- package/src/schemas/serialize/SchemTypeTool.tsx +4 -3
- package/src/schemas/serialize/serializeSchema.test.ts +3 -2
- package/src/schemas/serialize/serializeSchema.ts +15 -14
- package/src/schemas/serializedSchemaTypeSchema.ts +2 -1
- package/src/translate/FieldTranslationProvider.tsx +33 -25
- package/src/translate/getLanguageParams.ts +4 -4
- package/src/translate/paths.test.ts +11 -4
- package/src/translate/paths.ts +12 -11
- package/src/translate/translateActions.tsx +12 -11
- package/src/translate/types.ts +2 -2
- package/src/useApiClient.ts +9 -9
- package/dist/index.cjs.mjs +0 -7
|
@@ -1,33 +1,34 @@
|
|
|
1
|
+
import {ControlsIcon, SparklesIcon} from '@sanity/icons'
|
|
2
|
+
import {useCallback, useMemo, useRef} from 'react'
|
|
1
3
|
import {
|
|
2
|
-
DocumentFieldAction,
|
|
3
|
-
DocumentFieldActionGroup,
|
|
4
|
-
DocumentFieldActionItem,
|
|
5
|
-
ObjectSchemaType,
|
|
4
|
+
type DocumentFieldAction,
|
|
5
|
+
type DocumentFieldActionGroup,
|
|
6
|
+
type DocumentFieldActionItem,
|
|
7
|
+
type ObjectSchemaType,
|
|
6
8
|
typed,
|
|
7
9
|
useCurrentUser,
|
|
8
10
|
} from 'sanity'
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import {pluginTitleShort} from '../constants'
|
|
12
|
-
import {useAssistSupported} from '../helpers/useAssistSupported'
|
|
11
|
+
import {useDocumentPane} from 'sanity/structure'
|
|
12
|
+
|
|
13
13
|
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
14
|
-
import {getInstructionTitle, usePathKey} from '../helpers/misc'
|
|
15
|
-
import {documentRootKey, fieldPathParam, instructionParam, StudioInstruction} from '../types'
|
|
16
|
-
import {aiInspectorId} from '../assistInspector/constants'
|
|
17
14
|
import {getIcon} from '../assistDocument/components/instruction/appearance/IconInput'
|
|
18
15
|
import {useAssistDocumentContextValue} from '../assistDocument/hooks/useAssistDocumentContextValue'
|
|
19
16
|
import {
|
|
20
17
|
getAssistableDocId,
|
|
21
18
|
useRequestRunInstruction,
|
|
22
19
|
} from '../assistDocument/RequestRunInstructionProvider'
|
|
23
|
-
import {
|
|
24
|
-
import {generateCaptionsActions} from './generateCaptionActions'
|
|
25
|
-
import {useDocumentPane} from 'sanity/desk'
|
|
20
|
+
import {aiInspectorId} from '../assistInspector/constants'
|
|
26
21
|
import {useSelectedField, useTypePath} from '../assistInspector/helpers'
|
|
22
|
+
import {pluginTitleShort} from '../constants'
|
|
27
23
|
import {isSchemaAssistEnabled} from '../helpers/assistSupported'
|
|
28
|
-
import {translateActions, TranslateProps} from '../translate/translateActions'
|
|
29
|
-
import {generateImagActions} from './generateImageActions'
|
|
30
24
|
import {getConditionalMembers} from '../helpers/conditionalMembers'
|
|
25
|
+
import {getInstructionTitle, usePathKey} from '../helpers/misc'
|
|
26
|
+
import {useAssistSupported} from '../helpers/useAssistSupported'
|
|
27
|
+
import {translateActions, type TranslateProps} from '../translate/translateActions'
|
|
28
|
+
import {documentRootKey, fieldPathParam, instructionParam, type StudioInstruction} from '../types'
|
|
29
|
+
import {generateCaptionsActions} from './generateCaptionActions'
|
|
30
|
+
import {generateImagActions} from './generateImageActions'
|
|
31
|
+
import {PrivateIcon} from './PrivateIcon'
|
|
31
32
|
|
|
32
33
|
function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
|
|
33
34
|
return node
|
|
@@ -87,9 +88,9 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
87
88
|
const fieldAssist = useMemo(
|
|
88
89
|
() =>
|
|
89
90
|
(assistDocument?.fields ?? []).find(
|
|
90
|
-
(f) => f.path === typePath || (pathKey === documentRootKey && f.path === pathKey)
|
|
91
|
+
(f) => f.path === typePath || (pathKey === documentRootKey && f.path === pathKey),
|
|
91
92
|
),
|
|
92
|
-
[assistDocument?.fields, pathKey, typePath]
|
|
93
|
+
[assistDocument?.fields, pathKey, typePath],
|
|
93
94
|
)
|
|
94
95
|
|
|
95
96
|
const fieldAssistKey = fieldAssist?._key
|
|
@@ -105,7 +106,7 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
105
106
|
documentId: assistableDocumentId,
|
|
106
107
|
documentIsAssistable,
|
|
107
108
|
documentSchemaType,
|
|
108
|
-
})
|
|
109
|
+
}),
|
|
109
110
|
)
|
|
110
111
|
const manageInstructions = useCallback(
|
|
111
112
|
() =>
|
|
@@ -115,7 +116,7 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
115
116
|
[fieldPathParam]: pathKey,
|
|
116
117
|
[instructionParam]: undefined as any,
|
|
117
118
|
}),
|
|
118
|
-
[openInspector, closeInspector, isSelected, pathKey]
|
|
119
|
+
[openInspector, closeInspector, isSelected, pathKey],
|
|
119
120
|
)
|
|
120
121
|
|
|
121
122
|
const onInstructionAction = useCallback(
|
|
@@ -134,23 +135,23 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
134
135
|
: [],
|
|
135
136
|
})
|
|
136
137
|
},
|
|
137
|
-
[requestRunInstruction, assistableDocId, pathKey, typePath, assistDocumentId, fieldAssistKey]
|
|
138
|
+
[requestRunInstruction, assistableDocId, pathKey, typePath, assistDocumentId, fieldAssistKey],
|
|
138
139
|
)
|
|
139
140
|
|
|
140
141
|
const privateInstructions = useMemo(
|
|
141
142
|
() =>
|
|
142
143
|
fieldAssist?.instructions?.filter((i) => i.userId && i.userId === currentUser?.id) || [],
|
|
143
|
-
[fieldAssist?.instructions, currentUser]
|
|
144
|
+
[fieldAssist?.instructions, currentUser],
|
|
144
145
|
)
|
|
145
146
|
|
|
146
147
|
const sharedInstructions = useMemo(
|
|
147
148
|
() => fieldAssist?.instructions?.filter((i) => !i.userId) || [],
|
|
148
|
-
[fieldAssist?.instructions]
|
|
149
|
+
[fieldAssist?.instructions],
|
|
149
150
|
)
|
|
150
151
|
|
|
151
152
|
const instructions = useMemo(
|
|
152
153
|
() => [...privateInstructions, ...sharedInstructions],
|
|
153
|
-
[privateInstructions, sharedInstructions]
|
|
154
|
+
[privateInstructions, sharedInstructions],
|
|
154
155
|
)
|
|
155
156
|
|
|
156
157
|
const runInstructionsGroup = useMemo(() => {
|
|
@@ -160,7 +161,7 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
160
161
|
icon: () => null,
|
|
161
162
|
title: 'Run instructions',
|
|
162
163
|
children: [
|
|
163
|
-
...instructions?.map((instruction) =>
|
|
164
|
+
...(instructions?.map((instruction) =>
|
|
164
165
|
instructionItem({
|
|
165
166
|
instruction,
|
|
166
167
|
isPrivate: Boolean(instruction.userId && instruction.userId === currentUser?.id),
|
|
@@ -168,8 +169,8 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
168
169
|
hidden: isHidden,
|
|
169
170
|
documentIsNew: !!documentIsNew,
|
|
170
171
|
assistSupported,
|
|
171
|
-
})
|
|
172
|
-
),
|
|
172
|
+
}),
|
|
173
|
+
) || []),
|
|
173
174
|
imageCaptionAction,
|
|
174
175
|
imageGenAction,
|
|
175
176
|
].filter((a): a is DocumentFieldActionItem => !!a),
|
|
@@ -199,7 +200,7 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
199
200
|
onAction: manageInstructions,
|
|
200
201
|
selected: isSelected,
|
|
201
202
|
}),
|
|
202
|
-
[manageInstructions, isSelected]
|
|
203
|
+
[manageInstructions, isSelected],
|
|
203
204
|
)
|
|
204
205
|
|
|
205
206
|
const group = useMemo(
|
|
@@ -227,7 +228,7 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
227
228
|
imageCaptionAction,
|
|
228
229
|
translateAction,
|
|
229
230
|
imageGenAction,
|
|
230
|
-
]
|
|
231
|
+
],
|
|
231
232
|
)
|
|
232
233
|
|
|
233
234
|
const emptyAction = useMemo(
|
|
@@ -241,7 +242,7 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
241
242
|
title: pluginTitleShort,
|
|
242
243
|
selected: isSelected,
|
|
243
244
|
}),
|
|
244
|
-
[assistSupported, manageInstructions, isSelected]
|
|
245
|
+
[assistSupported, manageInstructions, isSelected],
|
|
245
246
|
)
|
|
246
247
|
|
|
247
248
|
// If there are no instructions, we don't want to render the group
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {DocumentFieldAction, DocumentFieldActionGroup, DocumentFieldActionItem} from 'sanity'
|
|
2
1
|
import {ImageIcon} from '@sanity/icons'
|
|
2
|
+
import {Box, Spinner} from '@sanity/ui'
|
|
3
3
|
import {useContext, useMemo} from 'react'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import type {DocumentFieldAction, DocumentFieldActionGroup, DocumentFieldActionItem} from 'sanity'
|
|
5
|
+
import {useDocumentPane} from 'sanity/structure'
|
|
6
|
+
|
|
7
7
|
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
8
|
-
import {ImageContext} from '../components/ImageContext'
|
|
9
|
-
import {Box, Spinner} from '@sanity/ui'
|
|
10
|
-
import {useDocumentPane} from 'sanity/desk'
|
|
11
8
|
import {aiInspectorId} from '../assistInspector/constants'
|
|
9
|
+
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
10
|
+
import {ImageContext} from '../components/ImageContext'
|
|
11
|
+
import {usePathKey} from '../helpers/misc'
|
|
12
12
|
import {fieldPathParam, instructionParam} from '../types'
|
|
13
|
+
import {canUseAssist, useApiClient, useGenerateCaption} from '../useApiClient'
|
|
13
14
|
|
|
14
15
|
function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
|
|
15
16
|
return node
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {DocumentFieldAction, DocumentFieldActionGroup, DocumentFieldActionItem} from 'sanity'
|
|
2
1
|
import {ImageIcon} from '@sanity/icons'
|
|
2
|
+
import {Box, Spinner} from '@sanity/ui'
|
|
3
3
|
import {useContext, useMemo} from 'react'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
4
|
+
import {DocumentFieldAction, DocumentFieldActionGroup, DocumentFieldActionItem} from 'sanity'
|
|
5
|
+
|
|
7
6
|
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
7
|
+
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
8
8
|
import {ImageContext} from '../components/ImageContext'
|
|
9
|
-
import {
|
|
9
|
+
import {usePathKey} from '../helpers/misc'
|
|
10
|
+
import {useApiClient, useGenerateImage} from '../useApiClient'
|
|
10
11
|
|
|
11
12
|
function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
|
|
12
13
|
return node
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {describe, expect, test} from 'vitest'
|
|
2
1
|
import {Schema} from '@sanity/schema'
|
|
3
2
|
import {ArraySchemaType, defineField, defineType, ObjectSchemaType} from 'sanity'
|
|
3
|
+
import {describe, expect, test} from 'vitest'
|
|
4
|
+
|
|
4
5
|
import {getConditionalMembers} from './conditionalMembers'
|
|
5
6
|
|
|
6
7
|
describe('conditionalMembers', () => {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/* eslint-disable max-depth */
|
|
2
2
|
import {
|
|
3
|
-
ArrayOfObjectsFormNode,
|
|
4
|
-
ArrayOfObjectsItemMember,
|
|
5
|
-
ArrayOfPrimitivesFormNode,
|
|
6
|
-
DocumentFormNode,
|
|
7
|
-
FieldsetState,
|
|
3
|
+
type ArrayOfObjectsFormNode,
|
|
4
|
+
type ArrayOfObjectsItemMember,
|
|
5
|
+
type ArrayOfPrimitivesFormNode,
|
|
6
|
+
type DocumentFormNode,
|
|
7
|
+
type FieldsetState,
|
|
8
8
|
isObjectSchemaType,
|
|
9
|
-
ObjectFormNode,
|
|
10
|
-
Path,
|
|
9
|
+
type ObjectFormNode,
|
|
10
|
+
type Path,
|
|
11
11
|
pathToString,
|
|
12
|
-
SchemaType,
|
|
12
|
+
type SchemaType,
|
|
13
13
|
} from 'sanity'
|
|
14
14
|
|
|
15
15
|
const MAX_DEPTH = 8
|
|
@@ -44,9 +44,12 @@ export function getConditionalMembers(docState: DocumentFormNode): ConditionalMe
|
|
|
44
44
|
readOnly: !!docState.readOnly,
|
|
45
45
|
conditional: typeof docState.schemaType.hidden === 'function',
|
|
46
46
|
}
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
return (
|
|
48
|
+
[doc, ...extractConditionalPaths(docState, MAX_DEPTH)]
|
|
49
|
+
.filter((v) => v.conditional)
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
+
.map(({conditional, ...state}) => ({...state}))
|
|
52
|
+
)
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
function isConditional(schemaType: SchemaType) {
|
|
@@ -68,7 +71,7 @@ function conditionalState(memberState: {
|
|
|
68
71
|
|
|
69
72
|
function extractConditionalPaths(
|
|
70
73
|
node: ObjectFormNode | FieldsetState,
|
|
71
|
-
maxDepth: number
|
|
74
|
+
maxDepth: number,
|
|
72
75
|
): ConditionalMemberInnerState[] {
|
|
73
76
|
if (node.path.length >= maxDepth) {
|
|
74
77
|
return []
|
|
@@ -90,7 +93,7 @@ function extractConditionalPaths(
|
|
|
90
93
|
|
|
91
94
|
let arrayPaths: ConditionalMemberInnerState[] = []
|
|
92
95
|
const isObjectsArray = array.members.some(
|
|
93
|
-
(m) => m.kind === 'item' && isObjectSchemaType(m.item.schemaType)
|
|
96
|
+
(m) => m.kind === 'item' && isObjectSchemaType(m.item.schemaType),
|
|
94
97
|
)
|
|
95
98
|
if (!array.readOnly) {
|
|
96
99
|
for (const arrayMember of array.members) {
|
|
@@ -112,7 +115,7 @@ function extractConditionalPaths(
|
|
|
112
115
|
return [...acc, conditionalState(member.field)]
|
|
113
116
|
} else if (member.kind === 'fieldSet') {
|
|
114
117
|
const conditionalFieldset = !!(node as ObjectFormNode).schemaType?.fieldsets?.some(
|
|
115
|
-
(f) => !f.single && f.name === member.fieldSet.name && typeof f.hidden === 'function'
|
|
118
|
+
(f) => !f.single && f.name === member.fieldSet.name && typeof f.hidden === 'function',
|
|
116
119
|
)
|
|
117
120
|
const innerFields = extractConditionalPaths(member.fieldSet, maxDepth).map((f) => ({
|
|
118
121
|
...f,
|
package/src/helpers/misc.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {documentRootKey, StudioInstruction} from '../types'
|
|
2
|
-
import {Path, pathToString} from 'sanity'
|
|
3
1
|
import {useMemo} from 'react'
|
|
2
|
+
import {Path, pathToString} from 'sanity'
|
|
3
|
+
|
|
4
|
+
import {documentRootKey, StudioInstruction} from '../types'
|
|
4
5
|
|
|
5
6
|
export function usePathKey(path: Path | string) {
|
|
6
7
|
return useMemo(() => {
|
package/src/helpers/typeUtils.ts
CHANGED
|
@@ -30,7 +30,7 @@ export function getDescriptionFieldOption(schemaType: SchemaType | undefined): s
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function getImageInstructionFieldOption(
|
|
33
|
-
schemaType: SchemaType | undefined
|
|
33
|
+
schemaType: SchemaType | undefined,
|
|
34
34
|
): string | undefined {
|
|
35
35
|
if (!schemaType) {
|
|
36
36
|
return undefined
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import {ArrowRightIcon, CheckmarkIcon, SparklesIcon} from '@sanity/icons'
|
|
1
2
|
import {Button, Card, Flex, Popover, Stack, Text} from '@sanity/ui'
|
|
2
3
|
import {useRef} from 'react'
|
|
4
|
+
|
|
3
5
|
import {AssistFeatureBadge} from '../components/AssistFeatureBadge'
|
|
4
|
-
import {ArrowRightIcon, CheckmarkIcon, SparklesIcon} from '@sanity/icons'
|
|
5
6
|
import {pluginTitle, releaseAnnouncementUrl} from '../constants'
|
|
6
7
|
|
|
7
8
|
export interface FieldActionsOnboardingProps {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {ObjectInputProps, FieldMember, pathToString} from 'sanity'
|
|
2
1
|
import {createContext, PropsWithChildren, useMemo} from 'react'
|
|
2
|
+
import {FieldMember, ObjectInputProps, pathToString} from 'sanity'
|
|
3
|
+
|
|
3
4
|
import {isAssistSupported} from '../helpers/assistSupported'
|
|
4
5
|
|
|
5
6
|
export const FirstAssistedPathContext = createContext<string | undefined>(undefined)
|
|
@@ -9,14 +10,14 @@ export interface FirstAssistedPathProviderProps {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export function FirstAssistedPathProvider(
|
|
12
|
-
props: PropsWithChildren<FirstAssistedPathProviderProps
|
|
13
|
+
props: PropsWithChildren<FirstAssistedPathProviderProps>,
|
|
13
14
|
) {
|
|
14
15
|
const {members} = props
|
|
15
16
|
|
|
16
17
|
const firstAssistedPath = useMemo(() => {
|
|
17
18
|
const firstAssisted = members.find(
|
|
18
19
|
(member): member is FieldMember =>
|
|
19
|
-
member.kind === 'field' && isAssistSupported(member.field.schemaType)
|
|
20
|
+
member.kind === 'field' && isAssistSupported(member.field.schemaType),
|
|
20
21
|
)
|
|
21
22
|
return firstAssisted?.field.path ? pathToString(firstAssisted?.field.path) : undefined
|
|
22
23
|
}, [members])
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {Box, Button, Container, Flex, Stack, Text} from '@sanity/ui'
|
|
2
1
|
import {SparklesIcon} from '@sanity/icons'
|
|
2
|
+
import {Box, Button, Container, Flex, Stack, Text} from '@sanity/ui'
|
|
3
|
+
import {styled} from 'styled-components'
|
|
4
|
+
|
|
3
5
|
import {releaseAnnouncementUrl} from '../constants'
|
|
4
|
-
import styled from 'styled-components'
|
|
5
6
|
|
|
6
7
|
const SparklesIllustration = styled(SparklesIcon)({
|
|
7
8
|
fontSize: '3.125em',
|
|
@@ -22,7 +22,7 @@ export function dismissFeatureOnboarding(featureKey: string) {
|
|
|
22
22
|
|
|
23
23
|
export function useOnboardingFeature(featureKey: string) {
|
|
24
24
|
const [showOnboarding, setShowOnboarding] = useState(
|
|
25
|
-
() => !isFeatureOnboardingDismissed(featureKey)
|
|
25
|
+
() => !isFeatureOnboardingDismissed(featureKey),
|
|
26
26
|
)
|
|
27
27
|
const dismissOnboarding = useCallback(() => {
|
|
28
28
|
setShowOnboarding(false)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// eslint-disable-next-line react/no-unused-prop-types
|
|
2
|
-
import {FormNodePresence} from 'sanity'
|
|
3
2
|
import {Card, Flex, Text, Tooltip} from '@sanity/ui'
|
|
3
|
+
import type {FormNodePresence} from 'sanity'
|
|
4
|
+
|
|
4
5
|
import {FadeInContent} from '../components/FadeInContent'
|
|
5
6
|
import {AssistAvatar} from './AssistAvatar'
|
|
6
7
|
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
9
|
export function AiFieldPresence(props: {presence: FormNodePresence}) {
|
|
8
10
|
return (
|
|
9
11
|
<Card style={{position: 'relative', background: 'transparent'}} contentEditable={false}>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {purple} from '@sanity/color'
|
|
2
2
|
import {SparklesIcon} from '@sanity/icons'
|
|
3
3
|
import {Text} from '@sanity/ui'
|
|
4
|
-
import {CSSProperties, useMemo} from 'react'
|
|
4
|
+
import {type CSSProperties, useMemo} from 'react'
|
|
5
5
|
import {useColorSchemeValue} from 'sanity'
|
|
6
|
-
import
|
|
6
|
+
import {keyframes, styled} from 'styled-components'
|
|
7
7
|
|
|
8
8
|
const Root = styled.span`
|
|
9
9
|
display: block;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Card, Flex} from '@sanity/ui'
|
|
2
2
|
import {useMemo} from 'react'
|
|
3
|
+
import {ObjectSchemaType} from 'sanity'
|
|
4
|
+
|
|
3
5
|
import {useAssistDocumentContextValue} from '../assistDocument/hooks/useAssistDocumentContextValue'
|
|
4
|
-
import {aiPresence} from './useAssistPresence'
|
|
5
6
|
import {documentRootKey, fieldPresenceTypeName} from '../types'
|
|
6
|
-
import {Card, Flex} from '@sanity/ui'
|
|
7
7
|
import {AiFieldPresence} from './AiFieldPresence'
|
|
8
|
+
import {aiPresence} from './useAssistPresence'
|
|
8
9
|
|
|
9
10
|
export function createAssistDocumentPresence(
|
|
10
11
|
documentId: string | undefined,
|
|
11
|
-
schemaType: ObjectSchemaType
|
|
12
|
+
schemaType: ObjectSchemaType,
|
|
12
13
|
) {
|
|
13
14
|
return function AssistDocumentPresenceWrapper() {
|
|
14
15
|
return documentId ? (
|
|
@@ -20,7 +21,7 @@ export function createAssistDocumentPresence(
|
|
|
20
21
|
function AssistDocumentPresence(props: {documentId: string; schemaType: ObjectSchemaType}) {
|
|
21
22
|
const {assistDocument} = useAssistDocumentContextValue(
|
|
22
23
|
props.documentId,
|
|
23
|
-
props.schemaType as ObjectSchemaType
|
|
24
|
+
props.schemaType as ObjectSchemaType,
|
|
24
25
|
)
|
|
25
26
|
const anyPresence = useMemo(() => {
|
|
26
27
|
const anyPresence = assistDocument?.tasks
|
|
@@ -41,7 +42,7 @@ function AssistDocumentPresence(props: {documentId: string; schemaType: ObjectSc
|
|
|
41
42
|
_key: anyRun._key,
|
|
42
43
|
_type: fieldPresenceTypeName,
|
|
43
44
|
},
|
|
44
|
-
[]
|
|
45
|
+
[],
|
|
45
46
|
)
|
|
46
47
|
: undefined
|
|
47
48
|
}, [assistDocument?.tasks])
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {useMemo} from 'react'
|
|
2
|
-
import {FormNodePresence, isKeySegment, Path, stringToPath} from 'sanity'
|
|
2
|
+
import {type FormNodePresence, isKeySegment, type Path, stringToPath} from 'sanity'
|
|
3
|
+
|
|
3
4
|
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
4
|
-
import {AiPresence} from '../types'
|
|
5
5
|
import {maxHistoryVisibilityMs, pluginTitle} from '../constants'
|
|
6
|
+
import type {AiPresence} from '../types'
|
|
6
7
|
|
|
7
8
|
const NO_PRESENCE: FormNodePresence[] = []
|
|
8
9
|
|
|
@@ -17,7 +18,8 @@ export function useAssistPresence(path: Path, showFocusWithin?: boolean): FormNo
|
|
|
17
18
|
?.flatMap((task) => task.presence ?? [])
|
|
18
19
|
?.filter(
|
|
19
20
|
(p) =>
|
|
20
|
-
p.started &&
|
|
21
|
+
p.started &&
|
|
22
|
+
new Date().getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs,
|
|
21
23
|
)
|
|
22
24
|
.filter((presence) => {
|
|
23
25
|
if (!presence.path || !path.length) {
|
|
@@ -48,6 +50,7 @@ export function useAssistPresence(path: Path, showFocusWithin?: boolean): FormNo
|
|
|
48
50
|
}, [showFocusWithin, tasks, path])
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
54
|
export function aiPresence(presence: AiPresence, path: Path, title?: string): FormNodePresence {
|
|
52
55
|
return {
|
|
53
56
|
user: {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {defineArrayMember, defineField, defineType, ObjectSchemaType} from 'sanity'
|
|
2
1
|
import {
|
|
3
2
|
ArrowRightIcon,
|
|
4
3
|
CodeIcon,
|
|
@@ -9,6 +8,25 @@ import {
|
|
|
9
8
|
SparklesIcon,
|
|
10
9
|
ThListIcon,
|
|
11
10
|
} from '@sanity/icons'
|
|
11
|
+
import {Box, Flex, Stack, Text, Tooltip} from '@sanity/ui'
|
|
12
|
+
import {createElement} from 'react'
|
|
13
|
+
import {defineArrayMember, defineField, defineType, ObjectSchemaType} from 'sanity'
|
|
14
|
+
|
|
15
|
+
import {AssistDocumentForm} from '../assistDocument/components/AssistDocumentForm'
|
|
16
|
+
import {FieldRefPreview} from '../assistDocument/components/FieldRefPreview'
|
|
17
|
+
import {HiddenFieldTitle} from '../assistDocument/components/generic/HiddenFieldTitle'
|
|
18
|
+
import {IconInput} from '../assistDocument/components/instruction/appearance/IconInput'
|
|
19
|
+
import {InstructionVisibility} from '../assistDocument/components/instruction/appearance/InstructionVisibility'
|
|
20
|
+
import {FieldRefPathInput} from '../assistDocument/components/instruction/FieldRefInput'
|
|
21
|
+
import {InstructionInput} from '../assistDocument/components/instruction/InstructionInput'
|
|
22
|
+
import {InstructionOutputField} from '../assistDocument/components/instruction/InstructionOutputField'
|
|
23
|
+
import {InstructionOutputInput} from '../assistDocument/components/instruction/InstructionOutputInput'
|
|
24
|
+
import {PromptInput} from '../assistDocument/components/instruction/PromptInput'
|
|
25
|
+
import {InstructionsArrayField} from '../assistDocument/components/InstructionsArrayField'
|
|
26
|
+
import {InstructionsArrayInput} from '../assistDocument/components/InstructionsArrayInput'
|
|
27
|
+
import {getFieldRefsWithDocument} from '../assistInspector/helpers'
|
|
28
|
+
import {instructionGuideUrl} from '../constants'
|
|
29
|
+
import {getInstructionTitle} from '../helpers/misc'
|
|
12
30
|
import {
|
|
13
31
|
assistDocumentIdPrefix,
|
|
14
32
|
assistDocumentTypeName,
|
|
@@ -23,24 +41,7 @@ import {
|
|
|
23
41
|
promptTypeName,
|
|
24
42
|
userInputTypeName,
|
|
25
43
|
} from '../types'
|
|
26
|
-
import {Box, Flex, Stack, Text, Tooltip} from '@sanity/ui'
|
|
27
|
-
import {getInstructionTitle} from '../helpers/misc'
|
|
28
|
-
import {AssistDocumentForm} from '../assistDocument/components/AssistDocumentForm'
|
|
29
|
-
import {InstructionInput} from '../assistDocument/components/instruction/InstructionInput'
|
|
30
|
-
import {HiddenFieldTitle} from '../assistDocument/components/generic/HiddenFieldTitle'
|
|
31
|
-
import {InstructionVisibility} from '../assistDocument/components/instruction/appearance/InstructionVisibility'
|
|
32
|
-
import {IconInput} from '../assistDocument/components/instruction/appearance/IconInput'
|
|
33
|
-
import {FieldRefPathInput} from '../assistDocument/components/instruction/FieldRefInput'
|
|
34
|
-
import {InstructionsArrayInput} from '../assistDocument/components/InstructionsArrayInput'
|
|
35
|
-
import {FieldRefPreview} from '../assistDocument/components/FieldRefPreview'
|
|
36
|
-
import {createElement} from 'react'
|
|
37
44
|
import {contextDocumentSchema} from './contextDocumentSchema'
|
|
38
|
-
import {PromptInput} from '../assistDocument/components/instruction/PromptInput'
|
|
39
|
-
import {instructionGuideUrl} from '../constants'
|
|
40
|
-
import {InstructionsArrayField} from '../assistDocument/components/InstructionsArrayField'
|
|
41
|
-
import {getFieldRefsWithDocument} from '../assistInspector/helpers'
|
|
42
|
-
import {InstructionOutputField} from '../assistDocument/components/instruction/InstructionOutputField'
|
|
43
|
-
import {InstructionOutputInput} from '../assistDocument/components/instruction/InstructionOutputInput'
|
|
44
45
|
|
|
45
46
|
export const fieldReference = defineType({
|
|
46
47
|
type: 'object',
|
|
@@ -346,7 +347,7 @@ export const instruction = defineType({
|
|
|
346
347
|
initialValue: (params, context) => context.currentUser?.id ?? '',
|
|
347
348
|
readOnly: (context) =>
|
|
348
349
|
Boolean(
|
|
349
|
-
context.parent?.createdById && context.parent?.createdById !== context.currentUser?.id
|
|
350
|
+
context.parent?.createdById && context.parent?.createdById !== context.currentUser?.id,
|
|
350
351
|
),
|
|
351
352
|
}),
|
|
352
353
|
defineField({
|
|
@@ -418,7 +419,7 @@ export const assistDocumentSchema = defineType({
|
|
|
418
419
|
|
|
419
420
|
components: {
|
|
420
421
|
input: AssistDocumentForm,
|
|
421
|
-
field: (props) => {
|
|
422
|
+
field: (props: any) => {
|
|
422
423
|
return props.renderDefault({...props, title: ''})
|
|
423
424
|
},
|
|
424
425
|
},
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {defineArrayMember, defineField, defineType} from 'sanity'
|
|
2
|
-
import {contextDocumentTypeName} from '../types'
|
|
3
1
|
import {DocumentTextIcon, TokenIcon} from '@sanity/icons'
|
|
2
|
+
import {defineArrayMember, defineField, defineType} from 'sanity'
|
|
3
|
+
|
|
4
4
|
import {HideReferenceChangedBannerInput} from '../components/HideReferenceChangedBannerInput'
|
|
5
|
+
import {contextDocumentTypeName} from '../types'
|
|
5
6
|
|
|
6
7
|
export const contextDocumentSchema = defineType({
|
|
7
8
|
type: 'document',
|
package/src/schemas/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
+
import {ArrayOfType, FieldProps, SchemaTypeDefinition} from 'sanity'
|
|
3
|
+
|
|
2
4
|
import {
|
|
3
5
|
assistDocumentSchema,
|
|
4
6
|
documentInstructionStatus,
|
|
@@ -13,7 +15,6 @@ import {
|
|
|
13
15
|
userInput,
|
|
14
16
|
} from './assistDocumentSchema'
|
|
15
17
|
import {contextDocumentSchema} from './contextDocumentSchema'
|
|
16
|
-
import {FieldProps, SchemaTypeDefinition, ArrayOfType} from 'sanity'
|
|
17
18
|
|
|
18
19
|
function excludeComments<T extends SchemaTypeDefinition | ArrayOfType>(type: T): T {
|
|
19
20
|
const existingRender = (type as any)?.components?.field
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {SyncIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Button, Card, Flex, Label, Spinner, Stack} from '@sanity/ui'
|
|
3
3
|
import {useCallback, useMemo, useState} from 'react'
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {useClient, useSchema} from 'sanity'
|
|
5
|
+
|
|
6
6
|
import {useListeningQuery} from '../../_lib/useListeningQuery'
|
|
7
|
+
import {assistSerializedTypeName, SerializedSchemaType} from '../../types'
|
|
7
8
|
import {serializeSchema} from './serializeSchema'
|
|
8
9
|
|
|
9
10
|
const NO_DATA: SerializedSchemaType[] = []
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {describe, expect, test} from 'vitest'
|
|
2
1
|
import {Schema} from '@sanity/schema'
|
|
3
|
-
import {serializeSchema} from './serializeSchema'
|
|
4
2
|
import {defineArrayMember, defineField, defineType} from 'sanity'
|
|
3
|
+
import {describe, expect, test} from 'vitest'
|
|
4
|
+
|
|
5
5
|
import {AssistOptions} from '../typeDefExtensions'
|
|
6
|
+
import {serializeSchema} from './serializeSchema'
|
|
6
7
|
|
|
7
8
|
const mockStudioTypes = [
|
|
8
9
|
defineField({
|